promise_pay 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -4
- data/lib/generators/templates/promise_pay_initializer.rb +0 -1
- data/lib/promise_pay/feelist.rb +67 -0
- data/lib/promise_pay/item.rb +4 -27
- data/lib/promise_pay/lib/dynamic_accessors.rb +52 -26
- data/lib/promise_pay/marketplace.rb +2 -2
- data/lib/promise_pay/request.rb +15 -6
- data/lib/promise_pay/session.rb +16 -16
- data/lib/promise_pay/user.rb +4 -22
- data/lib/promise_pay/version.rb +1 -1
- data/lib/promise_pay.rb +1 -1
- data/spec/promise_pay/feelist_spec.rb +66 -0
- data/spec/promise_pay/item_spec.rb +3 -3
- data/spec/promise_pay/marketplace_spec.rb +3 -3
- data/spec/promise_pay/request_spec.rb +26 -9
- data/spec/promise_pay/session_spec.rb +2 -2
- data/spec/promise_pay/user_spec.rb +3 -3
- data/spec/spec_helper.rb +1 -0
- data/spec/support/fixtures/feelist/create.json +14 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b3aff87096dc525f1caa87ff5dcdc139b60639a6
|
4
|
+
data.tar.gz: c43eeca819612307e63e294aa31559ab6c3c30dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a27f02557a1b4979866f6ff0838cb2a931dda180863ba13bc265130a1da173097ef1c4adc1c8386822561522e86024023b35bacec69afcf73059c867c12f0538
|
7
|
+
data.tar.gz: 6ba2e1df0596322db41773e7dffd7980fd6fa7bfe421c254b5cda399f10a0842f362513a310ee018e3fabe5805d31309c3259fae9388a439136406e53b3d0f7d
|
data/README.md
CHANGED
@@ -22,10 +22,6 @@ Generate your PromizePay API key and the rails promise_pay initializer:
|
|
22
22
|
|
23
23
|
$ rails generate promise_pay:init EMAIL PASSWORD
|
24
24
|
|
25
|
-
Set your fee-ids from PromisePay in config `config/initializers/promise_pay.rb`:
|
26
|
-
|
27
|
-
PromisePay.fee_ids = "abc-123"
|
28
|
-
|
29
25
|
You're set to go!
|
30
26
|
|
31
27
|
## Extra Info
|
@@ -42,6 +38,8 @@ Note this will overwrite anything in `config/initializers/promise_pay.rb`, but y
|
|
42
38
|
|
43
39
|
## Usage
|
44
40
|
|
41
|
+
All API interations, and therefore all params for these classes can be viewed at the official PromisePay doc website (http://docs.promisepay.com/).
|
42
|
+
|
45
43
|
```ruby
|
46
44
|
# A new PromisePay::Session that generates a session token
|
47
45
|
session = PromisePay::Session.new(session_params)
|
@@ -58,6 +56,10 @@ user.email => "email@addr"
|
|
58
56
|
item = PromisePay::Item.find("1s345")
|
59
57
|
item.amount => 10
|
60
58
|
|
59
|
+
# Create a fee returning a PromisePay::Feelist object
|
60
|
+
fee = PromisePay::Feelst.create(fee_params)
|
61
|
+
fee.id => "5c07f36a-d18f-4153-9a75-ebf9f4f2f9ef"
|
62
|
+
|
61
63
|
```
|
62
64
|
|
63
65
|
## Contributing
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require "promise_pay/lib/dynamic_accessors"
|
2
|
+
require "json"
|
3
|
+
|
4
|
+
module PromisePay
|
5
|
+
class Feelist
|
6
|
+
include Lib::DynamicAccessors
|
7
|
+
|
8
|
+
attr_reader :id
|
9
|
+
attr_reader :name
|
10
|
+
attr_reader :fee_type_id
|
11
|
+
attr_reader :amount
|
12
|
+
attr_reader :cap
|
13
|
+
attr_reader :min
|
14
|
+
attr_reader :max
|
15
|
+
attr_reader :to
|
16
|
+
|
17
|
+
def self.create(options = {})
|
18
|
+
new(options).create
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize(options = {})
|
22
|
+
@name = options.fetch(:name)
|
23
|
+
@fee_type_id = options.fetch(:fee_type_id)
|
24
|
+
@amount = options.fetch(:amount)
|
25
|
+
@cap = options.fetch(:cap)
|
26
|
+
@min = options.fetch(:min)
|
27
|
+
@max = options.fetch(:max)
|
28
|
+
@to = options.fetch(:to)
|
29
|
+
|
30
|
+
assign_instance_variables({'feelist' => options})
|
31
|
+
end
|
32
|
+
|
33
|
+
def create
|
34
|
+
assign_instance_variables(resource_result)
|
35
|
+
self
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def resource_result
|
41
|
+
request = PromisePay::Request.new(
|
42
|
+
path: api_resource,
|
43
|
+
method: :post,
|
44
|
+
payload: payload
|
45
|
+
)
|
46
|
+
|
47
|
+
response = request.execute
|
48
|
+
JSON.parse(response)["feelist"]
|
49
|
+
end
|
50
|
+
|
51
|
+
def api_resource
|
52
|
+
"feelist"
|
53
|
+
end
|
54
|
+
|
55
|
+
def payload
|
56
|
+
{
|
57
|
+
name: name,
|
58
|
+
fee_type_id: fee_type_id,
|
59
|
+
amount: amount,
|
60
|
+
cap: cap,
|
61
|
+
min: min,
|
62
|
+
max: max,
|
63
|
+
to: to
|
64
|
+
}
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/lib/promise_pay/item.rb
CHANGED
@@ -3,11 +3,14 @@ require "json"
|
|
3
3
|
|
4
4
|
module PromisePay
|
5
5
|
class Item
|
6
|
+
include Lib::DynamicAccessors
|
7
|
+
|
6
8
|
attr_reader :id
|
7
9
|
|
8
10
|
def initialize(id = nil, options = {})
|
9
11
|
@id = id
|
10
|
-
|
12
|
+
|
13
|
+
assign_instance_variables({'item' => options})
|
11
14
|
end
|
12
15
|
|
13
16
|
class << self
|
@@ -42,31 +45,5 @@ module PromisePay
|
|
42
45
|
def api_resource
|
43
46
|
"items/#{id}"
|
44
47
|
end
|
45
|
-
|
46
|
-
def assign_instance_variables(result)
|
47
|
-
result.each do |attribute, value|
|
48
|
-
if value.is_a?(Hash)
|
49
|
-
value.each { |att, val| initialize_property(att, val) }
|
50
|
-
else
|
51
|
-
initialize_property(attribute, value)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
self
|
55
|
-
end
|
56
|
-
|
57
|
-
def initialize_property(attribute, value)
|
58
|
-
attribute = attribute.gsub(/s$/, '_id') if ["buyers","sellers"].include? attribute
|
59
|
-
Lib::DynamicAccessors.define_accessor(attribute, value, self) unless accessor_defined?(attribute)
|
60
|
-
set_property(attribute, value)
|
61
|
-
end
|
62
|
-
|
63
|
-
def accessor_defined?(attribute)
|
64
|
-
respond_to?(attribute) && respond_to?("#{attribute}=")
|
65
|
-
end
|
66
|
-
|
67
|
-
def set_property(attribute, value)
|
68
|
-
setter_method = "#{attribute}="
|
69
|
-
self.send(setter_method, value)
|
70
|
-
end
|
71
48
|
end
|
72
49
|
end
|
@@ -1,41 +1,67 @@
|
|
1
1
|
module PromisePay
|
2
2
|
module Lib
|
3
3
|
module DynamicAccessors
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
def assign_instance_variables(result)
|
5
|
+
return if result.empty?
|
6
|
+
|
7
|
+
result.each do |attribute, value|
|
8
|
+
if value.is_a?(Hash)
|
9
|
+
value.each { |att, val| initialize_property(att, val) }
|
9
10
|
else
|
10
|
-
|
11
|
+
initialize_property(attribute, value)
|
11
12
|
end
|
12
13
|
end
|
14
|
+
self
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize_property(attribute, value)
|
18
|
+
attribute = attribute.gsub(/s$/, '_id') if ["buyers","sellers"].include? attribute
|
19
|
+
define_accessor(attribute, value, self) unless accessor_defined?(attribute)
|
20
|
+
set_property(attribute, value)
|
21
|
+
end
|
13
22
|
|
14
|
-
|
23
|
+
def accessor_defined?(attribute)
|
24
|
+
respond_to?(attribute) && respond_to?("#{attribute}=")
|
25
|
+
end
|
15
26
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
27
|
+
def set_property(attribute, value)
|
28
|
+
setter_method = "#{attribute}="
|
29
|
+
self.send(setter_method, value)
|
30
|
+
end
|
21
31
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
32
|
+
def define_accessor(attribute, value, object)
|
33
|
+
klass = object.class
|
34
|
+
if attribute.to_s.end_with? "_at"
|
35
|
+
define_date_based_accessors(attribute, value, klass)
|
36
|
+
else
|
37
|
+
define_standard_accessors(attribute, value, klass)
|
26
38
|
end
|
39
|
+
end
|
27
40
|
|
28
|
-
|
29
|
-
klass.class_eval %Q"
|
30
|
-
def #{attribute}=(value)
|
31
|
-
@#{attribute} = value
|
32
|
-
end
|
41
|
+
private
|
33
42
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
43
|
+
def define_date_based_accessors(attribute, value, klass)
|
44
|
+
klass.class_eval %Q"
|
45
|
+
def #{attribute}=(value)
|
46
|
+
@#{attribute} = value.nil? ? nil : Time.parse(value).to_i
|
47
|
+
end
|
48
|
+
|
49
|
+
def #{attribute}
|
50
|
+
@#{attribute}.nil? ? nil : Time.at(@#{attribute})
|
51
|
+
end
|
52
|
+
"
|
53
|
+
end
|
54
|
+
|
55
|
+
def define_standard_accessors(attribute, value, klass)
|
56
|
+
klass.class_eval %Q"
|
57
|
+
def #{attribute}=(value)
|
58
|
+
@#{attribute} = value
|
59
|
+
end
|
60
|
+
|
61
|
+
def #{attribute}
|
62
|
+
@#{attribute}
|
63
|
+
end
|
64
|
+
"
|
39
65
|
end
|
40
66
|
end
|
41
67
|
end
|
data/lib/promise_pay/request.rb
CHANGED
@@ -4,9 +4,11 @@ module PromisePay
|
|
4
4
|
class Request
|
5
5
|
|
6
6
|
def initialize(options = {})
|
7
|
-
@path = options.fetch
|
8
|
-
@user = options.fetch
|
9
|
-
@password = options.fetch
|
7
|
+
@path = options.fetch(:path)
|
8
|
+
@user = options.fetch(:user) { PromisePay.api_user }
|
9
|
+
@password = options.fetch(:password) { PromisePay.api_key }
|
10
|
+
@method = options.fetch(:method) { :get }
|
11
|
+
@payload = options.fetch(:payload) { nil }
|
10
12
|
@request = build_request
|
11
13
|
end
|
12
14
|
|
@@ -23,13 +25,18 @@ module PromisePay
|
|
23
25
|
private
|
24
26
|
|
25
27
|
def build_request
|
26
|
-
RestClient::Request.new(
|
27
|
-
|
28
|
+
RestClient::Request.new(request_params)
|
29
|
+
end
|
30
|
+
|
31
|
+
def request_params
|
32
|
+
{
|
33
|
+
method: method,
|
28
34
|
url: endpoint,
|
29
35
|
user: user,
|
30
36
|
password: password,
|
37
|
+
payload: payload,
|
31
38
|
headers: { accept: :json, content_type: :json }
|
32
|
-
|
39
|
+
}
|
33
40
|
end
|
34
41
|
|
35
42
|
def endpoint
|
@@ -47,6 +54,8 @@ module PromisePay
|
|
47
54
|
attr_reader :path
|
48
55
|
attr_reader :user
|
49
56
|
attr_reader :password
|
57
|
+
attr_reader :method
|
58
|
+
attr_reader :payload
|
50
59
|
attr_reader :request
|
51
60
|
end
|
52
61
|
|
data/lib/promise_pay/session.rb
CHANGED
@@ -23,22 +23,22 @@ module PromisePay
|
|
23
23
|
attr_accessor :buyer_country
|
24
24
|
|
25
25
|
def initialize(options = {})
|
26
|
-
@current_user_id = options.fetch
|
27
|
-
@item_name = options.fetch
|
28
|
-
@amount = options.fetch
|
29
|
-
@seller_lastname = options.fetch
|
30
|
-
@seller_firstname = options.fetch
|
31
|
-
@buyer_lastname = options.fetch
|
32
|
-
@buyer_firstname = options.fetch
|
33
|
-
@seller_email = options.fetch
|
34
|
-
@buyer_email = options.fetch
|
35
|
-
@external_item_id = options.fetch
|
36
|
-
@external_seller_id = options.fetch
|
37
|
-
@external_buyer_id = options.fetch
|
38
|
-
@fee_ids = options.fetch
|
39
|
-
@payment_type_id = options.fetch
|
40
|
-
@seller_country = options.fetch
|
41
|
-
@buyer_country = options.fetch
|
26
|
+
@current_user_id = options.fetch(:current_user_id) { nil }
|
27
|
+
@item_name = options.fetch(:item_name) { nil }
|
28
|
+
@amount = options.fetch(:amount) { nil }
|
29
|
+
@seller_lastname = options.fetch(:seller_lastname) { nil }
|
30
|
+
@seller_firstname = options.fetch(:seller_firstname) { nil }
|
31
|
+
@buyer_lastname = options.fetch(:buyer_lastname) { nil }
|
32
|
+
@buyer_firstname = options.fetch(:buyer_firstname) { nil }
|
33
|
+
@seller_email = options.fetch(:seller_email) { nil }
|
34
|
+
@buyer_email = options.fetch(:buyer_email) { nil }
|
35
|
+
@external_item_id = options.fetch(:external_item_id) { nil }
|
36
|
+
@external_seller_id = options.fetch(:external_seller_id) { nil }
|
37
|
+
@external_buyer_id = options.fetch(:external_buyer_id) { nil }
|
38
|
+
@fee_ids = options.fetch(:fee_ids) { nil }
|
39
|
+
@payment_type_id = options.fetch(:payment_type_id) { nil }
|
40
|
+
@seller_country = options.fetch(:seller_country) { nil }
|
41
|
+
@buyer_country = options.fetch(:buyer_country) { nil }
|
42
42
|
end
|
43
43
|
|
44
44
|
def request_token
|
data/lib/promise_pay/user.rb
CHANGED
@@ -3,11 +3,14 @@ require "json"
|
|
3
3
|
|
4
4
|
module PromisePay
|
5
5
|
class User
|
6
|
+
include Lib::DynamicAccessors
|
7
|
+
|
6
8
|
attr_reader :id
|
7
9
|
|
8
10
|
def initialize(id = nil, options = {})
|
9
11
|
@id = id
|
10
|
-
|
12
|
+
|
13
|
+
assign_instance_variables({'user' => options})
|
11
14
|
end
|
12
15
|
|
13
16
|
class << self
|
@@ -42,26 +45,5 @@ module PromisePay
|
|
42
45
|
def api_resource
|
43
46
|
"users/#{id}"
|
44
47
|
end
|
45
|
-
|
46
|
-
def assign_instance_variables(result)
|
47
|
-
result["user"].each do |attribute, value|
|
48
|
-
initialize_property(attribute, value)
|
49
|
-
end
|
50
|
-
self
|
51
|
-
end
|
52
|
-
|
53
|
-
def initialize_property(attribute, value)
|
54
|
-
Lib::DynamicAccessors.define_accessor(attribute, value, self) unless accessor_defined?(attribute)
|
55
|
-
set_property(attribute, value)
|
56
|
-
end
|
57
|
-
|
58
|
-
def accessor_defined?(attribute)
|
59
|
-
respond_to?(attribute) && respond_to?("#{attribute}=")
|
60
|
-
end
|
61
|
-
|
62
|
-
def set_property(attribute, value)
|
63
|
-
setter_method = "#{attribute}="
|
64
|
-
self.send(setter_method, value)
|
65
|
-
end
|
66
48
|
end
|
67
49
|
end
|
data/lib/promise_pay/version.rb
CHANGED
data/lib/promise_pay.rb
CHANGED
@@ -3,6 +3,7 @@ require "promise_pay/marketplace"
|
|
3
3
|
require "promise_pay/request"
|
4
4
|
require "promise_pay/session"
|
5
5
|
require "promise_pay/user"
|
6
|
+
require "promise_pay/feelist"
|
6
7
|
require "promise_pay/version"
|
7
8
|
require "promise_pay/collection"
|
8
9
|
require "promise_pay/country"
|
@@ -15,7 +16,6 @@ module PromisePay
|
|
15
16
|
attr_accessor :api_user
|
16
17
|
attr_accessor :api_key
|
17
18
|
attr_accessor :env
|
18
|
-
attr_accessor :fee_ids
|
19
19
|
end
|
20
20
|
|
21
21
|
class InvalidRequest < StandardError; end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe PromisePay::Feelist do
|
4
|
+
let(:request) { double("PromisePay::Request", execute: sample_response) }
|
5
|
+
|
6
|
+
before do
|
7
|
+
allow(PromisePay::Request).to receive(:new) { request }
|
8
|
+
end
|
9
|
+
|
10
|
+
describe ".create" do
|
11
|
+
let(:sample_response) { File.read("./spec/support/fixtures/feelist/create.json") }
|
12
|
+
|
13
|
+
let(:params) do
|
14
|
+
{
|
15
|
+
name: "Transaction fee",
|
16
|
+
fee_type_id: 1,
|
17
|
+
amount: 1500,
|
18
|
+
cap: nil,
|
19
|
+
min: nil,
|
20
|
+
max: nil,
|
21
|
+
to: 'seller'
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
it "returns a PromisePay::Feelist object" do
|
26
|
+
expect(described_class.create(params)).to be_a_kind_of PromisePay::Feelist
|
27
|
+
end
|
28
|
+
|
29
|
+
it "PromisePay::Feelist has correctly assigned attributes" do
|
30
|
+
promise_pay_fee = described_class.create(params)
|
31
|
+
|
32
|
+
expect(promise_pay_fee.id).to eq "5c07f36a-d18f-4153-9a75-ebf9f4f2f9ef"
|
33
|
+
expect(promise_pay_fee.name).to eq "Transaction fee"
|
34
|
+
expect(promise_pay_fee.fee_type_id).to eq 1
|
35
|
+
expect(promise_pay_fee.amount).to eq 1500
|
36
|
+
expect(promise_pay_fee.cap).to eq nil
|
37
|
+
expect(promise_pay_fee.min).to eq nil
|
38
|
+
expect(promise_pay_fee.max).to eq nil
|
39
|
+
expect(promise_pay_fee.to).to eq 'seller'
|
40
|
+
end
|
41
|
+
|
42
|
+
it "instantiates PromisePay::Request with the correct path" do
|
43
|
+
expect(PromisePay::Request).
|
44
|
+
to receive(:new).
|
45
|
+
with(hash_including(path: 'feelist'))
|
46
|
+
|
47
|
+
described_class.create(params)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "instantiates PromisePay::Request with the correct method" do
|
51
|
+
expect(PromisePay::Request).
|
52
|
+
to receive(:new).
|
53
|
+
with(hash_including(method: :post))
|
54
|
+
|
55
|
+
described_class.create(params)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "instantiates PromisePay::Request with the correct payload" do
|
59
|
+
expect(PromisePay::Request).
|
60
|
+
to receive(:new).
|
61
|
+
with(hash_including(payload: params))
|
62
|
+
|
63
|
+
described_class.create(params)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -4,7 +4,7 @@ describe PromisePay::Item do
|
|
4
4
|
let(:request) { double("PromisePay::Request", execute: sample_response) }
|
5
5
|
|
6
6
|
before do
|
7
|
-
PromisePay::Request.
|
7
|
+
allow(PromisePay::Request).to receive(:new) { request }
|
8
8
|
end
|
9
9
|
|
10
10
|
describe ".find" do
|
@@ -31,7 +31,7 @@ describe PromisePay::Item do
|
|
31
31
|
|
32
32
|
it "instantiates PromisePay::Request with the correct path" do
|
33
33
|
valid_path = "items/#{item_id}"
|
34
|
-
PromisePay::Request.
|
34
|
+
expect(PromisePay::Request).to receive(:new).with(path: valid_path)
|
35
35
|
described_class.find(item_id)
|
36
36
|
end
|
37
37
|
end
|
@@ -54,7 +54,7 @@ describe PromisePay::Item do
|
|
54
54
|
|
55
55
|
it "instantiates PromisePay::Request with the correct path" do
|
56
56
|
valid_path = "items/"
|
57
|
-
PromisePay::Request.
|
57
|
+
expect(PromisePay::Request).to receive(:new).with(path: valid_path)
|
58
58
|
described_class.find_all
|
59
59
|
end
|
60
60
|
end
|
@@ -9,13 +9,13 @@ describe PromisePay::Marketplace do
|
|
9
9
|
let(:password) { "password" }
|
10
10
|
|
11
11
|
before do
|
12
|
-
PromisePay::Request.
|
12
|
+
allow(PromisePay::Request).to receive(:new) { request }
|
13
13
|
end
|
14
14
|
|
15
15
|
it "instantiates PromisePay::Request with the correct path" do
|
16
16
|
valid_path = "request_token"
|
17
17
|
|
18
|
-
PromisePay::Request.
|
18
|
+
expect(PromisePay::Request).to receive(:new).with(
|
19
19
|
path: valid_path,
|
20
20
|
user: user,
|
21
21
|
password: password
|
@@ -25,7 +25,7 @@ describe PromisePay::Marketplace do
|
|
25
25
|
end
|
26
26
|
|
27
27
|
it "returns the generated marketplace token" do
|
28
|
-
described_class.new(user: user, password: password).request_token.
|
28
|
+
expect(described_class.new(user: user, password: password).request_token).to eq("123abc")
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
@@ -18,31 +18,48 @@ describe PromisePay::Request do
|
|
18
18
|
expect(request).to be_an_instance_of PromisePay::Request
|
19
19
|
end
|
20
20
|
|
21
|
-
it "uses the test api when configured" do
|
22
|
-
expect { PromisePay.env = :test }.
|
23
|
-
to change { request.send(:endpoint).start_with? PromisePay::TEST_HOST }.
|
24
|
-
from(false).to(true)
|
25
|
-
end
|
26
|
-
|
27
21
|
it "builds a RestClient::Request" do
|
28
22
|
expect(request.send(:request)).to be_an_instance_of RestClient::Request
|
29
23
|
end
|
24
|
+
|
25
|
+
it "uses the test api endpoint when configured" do
|
26
|
+
PromisePay.env = :test
|
27
|
+
|
28
|
+
request_endpoint = request.send(:endpoint)
|
29
|
+
expect(request_endpoint.start_with?(PromisePay::TEST_HOST)).to eq(true)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "uses the production api endpoint when configured" do
|
33
|
+
PromisePay.env = :production
|
34
|
+
|
35
|
+
request_endpoint = request.send(:endpoint)
|
36
|
+
expect(request_endpoint.start_with?(PromisePay::API_HOST)).to eq(true)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "takes on optional request method arguement" do
|
40
|
+
request = described_class.new(path: "users/", method: :post)
|
41
|
+
expect(request.send(:method)).to eq(:post)
|
42
|
+
end
|
30
43
|
end
|
31
44
|
|
32
45
|
describe "#execute" do
|
33
46
|
it "calls the RestClient::Request to be exectued" do
|
34
47
|
rest_client_request = request.send(:request)
|
35
|
-
rest_client_request.
|
48
|
+
expect(rest_client_request).to receive(:execute)
|
36
49
|
request.execute
|
37
50
|
end
|
38
51
|
|
39
52
|
it "re-raises RestClient::Unauthorized exceptions" do
|
40
|
-
|
53
|
+
rest_client_request = request.send(:request)
|
54
|
+
allow(rest_client_request).to receive(:execute) { raise RestClient::Unauthorized }
|
55
|
+
|
41
56
|
expect { request.execute }.to raise_error PromisePay::RequestError
|
42
57
|
end
|
43
58
|
|
44
59
|
it "re-raises RestClient::BadRequest exceptions" do
|
45
|
-
|
60
|
+
rest_client_request = request.send(:request)
|
61
|
+
allow(rest_client_request).to receive(:execute) { raise RestClient::BadRequest }
|
62
|
+
|
46
63
|
expect { request.execute }.to raise_error PromisePay::RequestError
|
47
64
|
end
|
48
65
|
|
@@ -28,7 +28,7 @@ describe PromisePay::Session do
|
|
28
28
|
|
29
29
|
context "with valid params" do
|
30
30
|
before do
|
31
|
-
PromisePay::Request.
|
31
|
+
allow(PromisePay::Request).to receive(:new) { request }
|
32
32
|
end
|
33
33
|
|
34
34
|
it "returns the generated session token from PromisePay" do
|
@@ -42,7 +42,7 @@ describe PromisePay::Session do
|
|
42
42
|
|
43
43
|
it "instantiates PromisePay::Request with the correct path" do
|
44
44
|
valid_path = "request_session_token?#{valid_params.to_param}"
|
45
|
-
PromisePay::Request.
|
45
|
+
expect(PromisePay::Request).to receive(:new).with(path: valid_path)
|
46
46
|
session.request_token
|
47
47
|
end
|
48
48
|
end
|
@@ -4,7 +4,7 @@ describe PromisePay::User do
|
|
4
4
|
let(:request) { double("PromisePay::Request", execute: sample_response) }
|
5
5
|
|
6
6
|
before do
|
7
|
-
PromisePay::Request.
|
7
|
+
allow(PromisePay::Request).to receive(:new) { request }
|
8
8
|
end
|
9
9
|
|
10
10
|
describe ".find" do
|
@@ -30,7 +30,7 @@ describe PromisePay::User do
|
|
30
30
|
|
31
31
|
it "instantiates PromisePay::Request with the correct path" do
|
32
32
|
valid_path = "users/#{user_id}"
|
33
|
-
PromisePay::Request.
|
33
|
+
expect(PromisePay::Request).to receive(:new).with(path: valid_path)
|
34
34
|
described_class.find(user_id)
|
35
35
|
end
|
36
36
|
end
|
@@ -53,7 +53,7 @@ describe PromisePay::User do
|
|
53
53
|
|
54
54
|
it "instantiates PromisePay::Request with the correct path" do
|
55
55
|
valid_path = "users/"
|
56
|
-
PromisePay::Request.
|
56
|
+
expect(PromisePay::Request).to receive(:new).with(path: valid_path)
|
57
57
|
described_class.find_all
|
58
58
|
end
|
59
59
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,14 @@
|
|
1
|
+
{
|
2
|
+
"feelist": {
|
3
|
+
"uuid": "5c07f36a-d18f-4153-9a75-ebf9f4f2f9ef",
|
4
|
+
"name": "Transaction fee",
|
5
|
+
"fee_type_id": 1,
|
6
|
+
"amount": 1500,
|
7
|
+
"cap": null,
|
8
|
+
"min": null,
|
9
|
+
"max": null,
|
10
|
+
"to": "seller",
|
11
|
+
"id": "5c07f36a-d18f-4153-9a75-ebf9f4f2f9ef",
|
12
|
+
"href": "/feelist/5c07f36a-d18f-4153-9a75-ebf9f4f2f9ef"
|
13
|
+
}
|
14
|
+
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: promise_pay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Liam Norton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -112,6 +112,7 @@ files:
|
|
112
112
|
- lib/promise_pay.rb
|
113
113
|
- lib/promise_pay/collection.rb
|
114
114
|
- lib/promise_pay/country.rb
|
115
|
+
- lib/promise_pay/feelist.rb
|
115
116
|
- lib/promise_pay/item.rb
|
116
117
|
- lib/promise_pay/lib/dynamic_accessors.rb
|
117
118
|
- lib/promise_pay/marketplace.rb
|
@@ -121,12 +122,14 @@ files:
|
|
121
122
|
- lib/promise_pay/version.rb
|
122
123
|
- promise_pay.gemspec
|
123
124
|
- spec/promise_pay/country_spec.rb
|
125
|
+
- spec/promise_pay/feelist_spec.rb
|
124
126
|
- spec/promise_pay/item_spec.rb
|
125
127
|
- spec/promise_pay/marketplace_spec.rb
|
126
128
|
- spec/promise_pay/request_spec.rb
|
127
129
|
- spec/promise_pay/session_spec.rb
|
128
130
|
- spec/promise_pay/user_spec.rb
|
129
131
|
- spec/spec_helper.rb
|
132
|
+
- spec/support/fixtures/feelist/create.json
|
130
133
|
- spec/support/fixtures/item/find.json
|
131
134
|
- spec/support/fixtures/item/find_all.json
|
132
135
|
- spec/support/fixtures/token_generation.json
|
@@ -158,12 +161,14 @@ specification_version: 4
|
|
158
161
|
summary: PromisePay gem
|
159
162
|
test_files:
|
160
163
|
- spec/promise_pay/country_spec.rb
|
164
|
+
- spec/promise_pay/feelist_spec.rb
|
161
165
|
- spec/promise_pay/item_spec.rb
|
162
166
|
- spec/promise_pay/marketplace_spec.rb
|
163
167
|
- spec/promise_pay/request_spec.rb
|
164
168
|
- spec/promise_pay/session_spec.rb
|
165
169
|
- spec/promise_pay/user_spec.rb
|
166
170
|
- spec/spec_helper.rb
|
171
|
+
- spec/support/fixtures/feelist/create.json
|
167
172
|
- spec/support/fixtures/item/find.json
|
168
173
|
- spec/support/fixtures/item/find_all.json
|
169
174
|
- spec/support/fixtures/token_generation.json
|