slidepay 0.0.2 → 0.0.4

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: ea9149688f04b38ba2d7253f8805ebe167a518b9
4
- data.tar.gz: 925a135adacc97d7f5c25d653a10e4b08da01996
3
+ metadata.gz: 83778705a23a1f6a5e99703eb71378d771ddf692
4
+ data.tar.gz: a17a2085f2568a65c4e8048714b4917618e06c93
5
5
  SHA512:
6
- metadata.gz: 4c50c362f7d73afcd7da67a06a423affc13b1a4701041057af683a4b3c159e097aeaa91b3642fffb1871addd978b838fe7502845188fe6cd206fa94972f8d61f
7
- data.tar.gz: 37ea01471930e0a3691a3904c8b17a21dc8584e0e2f0025841088f4c80e1d3a5fdbfa78a3634351d91d32173eb8d1c195d9d6fd3468c5cfd11478d300a5164a3
6
+ metadata.gz: 7165aad1cdda93fd228367c5d823313270d7f3f6c457a17557cfbacb0411c859e24bd9c15cb4403dde6f912671d9b07057bb93e0df83c9c6f317c80ecb939e26
7
+ data.tar.gz: 927b27f371a156d55a7e428ae31ff8fe1a87226796e2e95f124604251619e68c941518fa727159687431176ebef43b48676dfbfda37000694db5f7337c0ffabb
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  # Slidepay Ruby Sdk
4
4
 
5
- [![Build Status](https://travis-ci.org/SlidePay/slidepay-ruby-sdk.png)](https://travis-ci.org/SlidePay/slidepay-ruby-sdk) [![Code Climate](https://codeclimate.com/repos/5236cb7013d6371e46004010/badges/f963bebb1565c5419c78/gpa.png)](https://codeclimate.com/repos/5236cb7013d6371e46004010/feed)
5
+ [![Gem Version](https://badge.fury.io/rb/slidepay.png)](http://badge.fury.io/rb/slidepay) [![Build Status](https://travis-ci.org/SlidePay/slidepay-ruby-sdk.png)](https://travis-ci.org/SlidePay/slidepay-ruby-sdk) [![Code Climate](https://codeclimate.com/repos/5236cb7013d6371e46004010/badges/f963bebb1565c5419c78/gpa.png)](https://codeclimate.com/repos/5236cb7013d6371e46004010/feed)
6
6
 
7
7
  First version of the SlidePay Ruby SDK
8
8
 
@@ -31,7 +31,7 @@ Check out our [main documentation](https://getcube.atlassian.net/wiki/display/CD
31
31
  Requests can be made three ways:
32
32
 
33
33
  1. Using the SlidePay request methods directly with the desired API url and relevant request JSON
34
- 2. [Coming Soon] Using an instance of the SlidePay::Client class to save an ApiResource, such as a payment, order, or item
34
+ 2. Using an instance of the SlidePay::Client class to save an ApiResource, such as a payment, bank_account, or api_key
35
35
  3. Using an instance of a SlidePay::ApiResource class, such as SlidePay::ApiKey or SlidePay::Payment
36
36
 
37
37
  ## Authentication
@@ -40,12 +40,14 @@ module SlidePay
40
40
 
41
41
  # Base Request Methods
42
42
  def get(request_params)
43
+ options = {}
43
44
  if request_params.is_a? String
44
- SlidePay.get(path: request_params, api_key: @api_key, token: @token, endpoint: @endpoint)
45
+ options = { :path => request_params, :api_key => @api_key, :token => @token, :endpoint => @endpoint }
45
46
  else
46
- request_params.merge! api_key: @api_key, token: @token, endpoint: @endpoint
47
- SlidePay.get(request_params)
47
+ options = request_params.merge! api_key: @api_key, token: @token, endpoint: @endpoint
48
48
  end
49
+
50
+ SlidePay.get(options)
49
51
  end
50
52
 
51
53
  def put(request_params)
@@ -59,12 +61,13 @@ module SlidePay
59
61
  end
60
62
 
61
63
  def delete(request_params)
64
+ options = {}
62
65
  if request_params.is_a? String
63
- SlidePay.delete(path: request_params, api_key: @api_key, token: @token, endpoint: @endpoint)
66
+ options = { :path => request_params, :api_key => @api_key, :token => @token, :endpoint => @endpoint }
64
67
  else
65
- request_params.merge! api_key: @api_key, token: @token, endpoint: @endpoint
66
- SlidePay.delete(request_params)
68
+ options = request_params.merge! api_key: @api_key, token: @token, endpoint: @endpoint
67
69
  end
70
+ SlidePay.delete(options)
68
71
  end
69
72
 
70
73
 
@@ -94,6 +97,5 @@ module SlidePay
94
97
  def destroy(resource)
95
98
  resource.destroy(api_key: @api_key, token: @token, endpoint: @endpoint)
96
99
  end
97
-
98
100
  end
99
101
  end
@@ -2,6 +2,10 @@ module SlidePay
2
2
  class ApiResource < Hash
3
3
  attr_accessor :url_root, :id_attribute, :token, :api_key, :endpoint
4
4
 
5
+ # These MUST be declared in the inheriting classes
6
+ URL_ROOT = ""
7
+ ID_ATTRIBUTE = ""
8
+
5
9
  def initialize(values_hash={})
6
10
  if values_hash[:url_root]
7
11
  @url_root = values_hash[:url_root]
@@ -113,5 +117,84 @@ module SlidePay
113
117
  false
114
118
  end
115
119
  end
120
+
121
+ class << self
122
+ def find_where(search_params, token=nil, api_key=nil, endpoint=nil)
123
+ sfa = []
124
+ search_params.each_pair do |k,v|
125
+ sfa.push(field: k, condition: "equals", value: v)
126
+ end
127
+
128
+ search_results = []
129
+ response = SlidePay.put(path: self::URL_ROOT, data: sfa.to_json, token: token, api_key: api_key, endpoint: endpoint)
130
+ if response.was_successful? and response.data != nil
131
+ data = response.data
132
+ data.each do |resource_hash|
133
+ search_results.push self.new(resource_hash)
134
+ end
135
+ end
136
+
137
+ search_results
138
+ end
139
+
140
+ def find_between(start_params, end_params, token=nil, api_key=nil, endpoint=nil)
141
+ sfa = []
142
+ start_params.each_pair do |k,v|
143
+ sfa.push(field: k, condition: "greater_than", value: v)
144
+ end
145
+
146
+ end_params.each_pair do |k,v|
147
+ sfa.push(field: k, condition: "less_than", value: v)
148
+ end
149
+
150
+ search_results = []
151
+ response = SlidePay.put(path: self::URL_ROOT, data: sfa.to_json, token: token, api_key: api_key, endpoint: endpoint)
152
+ if response.was_successful? and response.data != nil
153
+ data = response.data
154
+ data.each do |resource_hash|
155
+ search_results.push self.new(resource_hash)
156
+ end
157
+ end
158
+
159
+ search_results
160
+ end
161
+
162
+ def find_greater_than(search_params, token=nil, api_key=nil, endpoint=nil)
163
+ sfa = []
164
+ search_params.each_pair do |k,v|
165
+ sfa.push(field: k, condition: "greater_than", value: v)
166
+ end
167
+
168
+ search_results = []
169
+ response = SlidePay.put(path: self::URL_ROOT, data: sfa.to_json, token: token, api_key: api_key, endpoint: endpoint)
170
+ if response.was_successful? and response.data != nil
171
+ data = response.data
172
+ data.each do |resource_hash|
173
+ search_results.push self.new(resource_hash)
174
+ end
175
+ end
176
+
177
+ search_results
178
+ end
179
+
180
+ def find_less_than(search_params, token=nil, api_key=nil, endpoint=nil)
181
+ sfa = []
182
+ search_params.each_pair do |k,v|
183
+ sfa.push(field: k, condition: "less_than", value: v)
184
+ end
185
+
186
+ search_results = []
187
+ response = SlidePay.put(path: self::URL_ROOT, data: sfa.to_json, token: token, api_key: api_key, endpoint: endpoint)
188
+ if response.was_successful? and response.data != nil
189
+ data = response.data
190
+ data.each do |resource_hash|
191
+ search_results.push self.new(resource_hash)
192
+ end
193
+ end
194
+
195
+ search_results
196
+ end
197
+ end
198
+
116
199
  end
117
200
  end
@@ -1,5 +1,8 @@
1
1
  module SlidePay
2
2
  class Payment < ApiResource
3
+ URL_ROOT = "payment"
4
+ ID_ATTRIBUTE = "payment_id"
5
+
3
6
  def initialize(values_hash={})
4
7
  @id_attribute = "payment_id"
5
8
  @url_root = "payment"
@@ -1,3 +1,3 @@
1
1
  module SlidePay
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -0,0 +1,40 @@
1
+ $:.unshift(File.join(File.dirname(__FILE__), 'lib'))
2
+ $:.unshift(File.join(File.dirname(__FILE__), 'spec'))
3
+
4
+ require 'multi_json'
5
+ require 'slidepay'
6
+ require 'spec_helper'
7
+
8
+ include SlidePay
9
+
10
+ SlidePay.configure(development: true)
11
+ SlidePay.api_key = ENV["api_key"]
12
+
13
+ RestClient.proxy = "http://127.0.0.1:8888"
14
+
15
+ p = Payment.new
16
+ p["amount"] = 1.01
17
+ p["method"] = "CreditCard"
18
+ p["cc_number"] = "4111111111111111"
19
+ p["cc_cvv2"] = "111"
20
+ p["cc_billing_zip"] = "11111"
21
+ p["cc_expiry_month"] = "10"
22
+ p["cc_expiry_year"] = "14"
23
+ r = p.process()
24
+
25
+ if r
26
+ puts "Payment created with id: #{p.id}"
27
+
28
+ # Find the payment that was just created.
29
+ payments_found = Payment.find_where(payment_id: p.id)
30
+
31
+ puts "Payments found: #{payments_found.length}"
32
+ puts "============================================="
33
+ payments_found.each do |payment|
34
+ puts "#{payment.id} - #{payment["amount"]}"
35
+ end
36
+
37
+
38
+ else
39
+ puts "Payment failed. "
40
+ end
@@ -0,0 +1,26 @@
1
+ $:.unshift(File.join(File.dirname(__FILE__), 'lib'))
2
+ $:.unshift(File.join(File.dirname(__FILE__), 'spec'))
3
+
4
+ require 'multi_json'
5
+ require 'slidepay'
6
+ require 'spec_helper'
7
+
8
+ include SlidePay
9
+
10
+ SlidePay.configure(development: true)
11
+ SlidePay.api_key = ENV["api_key"]
12
+
13
+ RestClient.proxy = "http://127.0.0.1:8888"
14
+
15
+ # Find any payments in this company that are under review
16
+ payments_found = Payment.find_where(under_review: 1)
17
+
18
+ if payments_found.count > 0
19
+ puts "Payments found: #{payments_found.length}"
20
+ puts "============================================="
21
+ payments_found.each do |payment|
22
+ puts "#{payment.id} - #{payment["amount"]}"
23
+ end
24
+ else
25
+ puts "No payments found to be under review. Yay(?)"
26
+ end
@@ -224,4 +224,99 @@ describe SlidePay::ApiResource do
224
224
  expect(resource[:id]).to be_nil
225
225
  end
226
226
  end
227
+
228
+ describe "search" do
229
+ before(:all) do
230
+ SlidePay.stub(:put) { a_response_object(successful_array_response) }
231
+ end
232
+
233
+ it "should be represented by several instance methods" do
234
+ public_methods = SlidePay::ApiResource.public_methods
235
+
236
+ expect(public_methods.include?(:find_where)).to be_true
237
+ expect(public_methods.include?(:find_greater_than)).to be_true
238
+ expect(public_methods.include?(:find_less_than)).to be_true
239
+ expect(public_methods.include?(:find_between)).to be_true
240
+ end
241
+
242
+ describe "find_where" do
243
+ it "should raise an error if no parameters are supplied" do
244
+ expect{ SlidePay::ApiResource.find_where }.to raise_error
245
+ end
246
+
247
+ it "should accept a hash" do
248
+ expect { SlidePay::ApiResource.find_where(created: "12/13/2013") }.not_to raise_error
249
+ end
250
+
251
+ it "should return an array of resources" do
252
+ expect(SlidePay::ApiResource.find_where(created: "12/13/2013")).to be_a(Array)
253
+ end
254
+
255
+ it "should make a put request" do
256
+ SlidePay.should_receive(:put).and_return(a_response_object(successful_array_response))
257
+ SlidePay::ApiResource.find_where(created: "12/13/2013")
258
+ end
259
+ end
260
+
261
+ describe "find_greater_than" do
262
+ it "should raise an error if no parameters are supplied" do
263
+ expect{ SlidePay::ApiResource.find_greater_than }.to raise_error
264
+ end
265
+
266
+ it "should accept a hash" do
267
+ expect { SlidePay::ApiResource.find_greater_than(created: "12/13/2013") }.not_to raise_error
268
+ end
269
+
270
+ it "should return an array of resources" do
271
+ expect(SlidePay::ApiResource.find_greater_than(created: "12/13/2013")).to be_a(Array)
272
+ end
273
+
274
+ it "should make a put request" do
275
+ SlidePay.should_receive(:put).and_return(a_response_object(successful_array_response))
276
+ SlidePay::ApiResource.find_greater_than(created: "12/13/2013")
277
+ end
278
+ end
279
+
280
+ describe "find_less_than" do
281
+ it "should raise an error if no parameters are supplied" do
282
+ expect{ SlidePay::ApiResource.find_less_than }.to raise_error
283
+ end
284
+
285
+ it "should accept a hash" do
286
+ expect { SlidePay::ApiResource.find_less_than(created: "12/13/2013") }.not_to raise_error
287
+ end
288
+
289
+ it "should return an array of resources" do
290
+ expect(SlidePay::ApiResource.find_less_than(created: "12/13/2013")).to be_a(Array)
291
+ end
292
+
293
+ it "should make a put request" do
294
+ SlidePay.should_receive(:put).and_return(a_response_object(successful_array_response))
295
+ SlidePay::ApiResource.find_less_than(created: "12/13/2013")
296
+ end
297
+ end
298
+
299
+ describe "find_between" do
300
+ it "should raise an error if no parameters are supplied" do
301
+ expect{ SlidePay::ApiResource.find_between }.to raise_error
302
+ end
303
+
304
+ it "should return an array of resources" do
305
+ SlidePay.should_receive(:put).and_return(a_response_object(successful_array_response))
306
+
307
+ expect(SlidePay::ApiResource.find_between(
308
+ { :created => "12/13/2013" },
309
+ { :created => "12/14/2013" }
310
+ )).to be_a(Array)
311
+ end
312
+
313
+ it "should make a put request" do
314
+ SlidePay.should_receive(:put).and_return(a_response_object(successful_array_response))
315
+ expect(SlidePay::ApiResource.find_between(
316
+ { :created => "12/13/2013" },
317
+ { :created => "12/14/2013" }
318
+ )).to be_a(Array)
319
+ end
320
+ end
321
+ end
227
322
  end
@@ -2,6 +2,16 @@ require "slidepay"
2
2
  require "spec_helper"
3
3
 
4
4
  describe SlidePay::Payment do
5
+ describe "class constants" do
6
+ it "should include an id_attribute" do
7
+ expect(SlidePay::Payment::ID_ATTRIBUTE).to eq("payment_id")
8
+ end
9
+
10
+ it "should include a root url" do
11
+ expect(SlidePay::Payment::URL_ROOT).to eq("payment")
12
+ end
13
+ end
14
+
5
15
  it "should have an id_attribute" do
6
16
  p = SlidePay::Payment.new()
7
17
  expect(p.id_attribute).to eq("payment_id")
@@ -87,4 +97,53 @@ describe SlidePay::Payment do
87
97
  expect(p.refund()).to eq(true)
88
98
  end
89
99
  end
100
+
101
+ describe "class methods" do
102
+ describe "search" do
103
+ it "should be represented by several instance methods" do
104
+ public_methods = SlidePay::Payment.public_methods
105
+
106
+ expect(public_methods.include?(:find_where)).to be_true
107
+ expect(public_methods.include?(:find_greater_than)).to be_true
108
+ expect(public_methods.include?(:find_less_than)).to be_true
109
+ expect(public_methods.include?(:find_between)).to be_true
110
+ end
111
+
112
+ describe "find_where" do
113
+ it "should make a put request to /payment" do
114
+ SlidePay.should_receive(:put)
115
+ .with(path: "payment", data: payment_where_sfa.to_json, token: nil, api_key: nil, endpoint: nil)
116
+ .and_return(a_response_object(payment_search_response))
117
+ SlidePay::Payment.find_where(created: "12/13/2013")
118
+ end
119
+ end
120
+
121
+ describe "find_less_than" do
122
+ it "should make a put request to /payment" do
123
+ SlidePay.should_receive(:put)
124
+ .with(path: "payment", data: payment_less_than_sfa.to_json, token: nil, api_key: nil, endpoint: nil)
125
+ .and_return(a_response_object(payment_search_response))
126
+ SlidePay::Payment.find_less_than(created: "10/08/2012")
127
+ end
128
+ end
129
+
130
+ describe "find_greater_than" do
131
+ it "should make a put request to /payment" do
132
+ SlidePay.should_receive(:put)
133
+ .with(path: "payment", data: payment_greater_than_sfa.to_json, token: nil, api_key: nil, endpoint: nil)
134
+ .and_return(a_response_object(payment_search_response))
135
+ SlidePay::Payment.find_greater_than(created: "10/08/2013 23:28:40")
136
+ end
137
+ end
138
+
139
+ describe "find_between" do
140
+ it "should make a put request to /payment" do
141
+ SlidePay.should_receive(:put)
142
+ .with(path: "payment", data: payment_between_sfa.to_json, token: nil, api_key: nil, endpoint: nil)
143
+ .and_return(a_response_object(payment_search_response))
144
+ SlidePay::Payment.find_between({:created => "10/08/2013 23:28"}, {:created => "10/08/2013 23:28:40"})
145
+ end
146
+ end
147
+ end
148
+ end
90
149
  end
@@ -254,6 +254,115 @@ def successful_array_response
254
254
  eos
255
255
  end
256
256
 
257
+ def payment_where_sfa
258
+ [{ :field => "created", :condition => "equals", :value => "12/13/2013" }]
259
+ end
260
+
261
+ def payment_greater_than_sfa
262
+ [{ field: "created", condition: "greater_than", value: "10/08/2013 23:28:40"}]
263
+ end
264
+
265
+ def payment_less_than_sfa
266
+ [{ field: "created", condition: "less_than", value: "10/08/2012"}]
267
+ end
268
+
269
+ def payment_between_sfa
270
+ [{ field: "created", condition: "greater_than", value: "10/08/2013 23:28"},
271
+ { field: "created", condition: "less_than", value: "10/08/2013 23:28:40"}]
272
+ end
273
+
274
+ def payment_search_response
275
+ <<-eos
276
+ {
277
+ "success": true,
278
+ "custom": null,
279
+ "operation": "PUT search payment",
280
+ "endpoint": "https://dev.getcube.com:65532",
281
+ "timezone": "",
282
+ "method": "put",
283
+ "obj": "payment",
284
+ "id": 0,
285
+ "milliseconds": "15.62",
286
+ "data": [
287
+ {
288
+ "payment_id": 10923,
289
+ "order_master_id": 4133,
290
+ "company_id": 18,
291
+ "location_id": 14,
292
+ "customer_id": 0,
293
+ "user_master_id": 32,
294
+ "auto_capture": 1,
295
+ "device_type": "",
296
+ "method": "CreditCard",
297
+ "method_other": "",
298
+ "stored_payment_guid": "6f9a90c4-69c3-41cc-8dcd-299a0b6915c3",
299
+ "cc_type": "Visa",
300
+ "cc_present": 0,
301
+ "cc_number": "4111111111111111",
302
+ "cc_expiry_month": "11",
303
+ "cc_expiry_year": "11",
304
+ "cc_name_on_card": "",
305
+ "cc_address_1": "",
306
+ "cc_address_2": "",
307
+ "cc_address_3": "",
308
+ "cc_city": "",
309
+ "cc_state": "",
310
+ "cc_billing_zip": "11111",
311
+ "cc_country": "",
312
+ "cc_track1data": "",
313
+ "cc_track2data": "",
314
+ "cc_cvv2": "",
315
+ "cc_redacted_number": "************1111",
316
+ "encryption_vendor": "",
317
+ "encryption_ksn": "",
318
+ "encryption_device_serial": "",
319
+ "amount": 14.01,
320
+ "tip_amount": 0.00,
321
+ "is_refund": null,
322
+ "refund_payment_id": null,
323
+ "is_chargeback": 0,
324
+ "under_review": 0,
325
+ "notes": "Goods or Services",
326
+ "signature_cloud_object_id": null,
327
+ "provider": "ipcommerce-cube-vantiv",
328
+ "provider_payment_token": "",
329
+ "provider_transaction_token": "DummyTransaction",
330
+ "provider_is_approved": "true",
331
+ "provider_status_code": "00",
332
+ "provider_status_message": "Transaction Approved",
333
+ "provider_transaction_state": "Authorized",
334
+ "provider_approval_code": "000000",
335
+ "provider_capture_state": "DummyTransaction",
336
+ "provider_capture_status_message": "",
337
+ "settlement_transaction_token": "",
338
+ "provider_fee_amount": 0.00,
339
+ "vendor_id": "cube",
340
+ "vendor_markup_percent": 0.00,
341
+ "vendor_markup_pertrans": 0.00,
342
+ "fee_percentage": 3.50,
343
+ "fee_percentage_amount": 0.50,
344
+ "fee_per_transaction": 0.00,
345
+ "fee_interchange": null,
346
+ "fee_total": 0.50,
347
+ "ip_address": "50.152.207.105",
348
+ "latitude": "38.0000",
349
+ "longitude": "-97.0000",
350
+ "country": "US",
351
+ "distance_from_location": 1368.70,
352
+ "processor_time_ms": 0.00,
353
+ "total_time_ms": null,
354
+ "capture_requested": null,
355
+ "capture_confirmed": null,
356
+ "created": "2013-10-08T23:29:01",
357
+ "last_update": "2013-10-08T23:29:01"
358
+ }
359
+ ],
360
+ "data_md5": "96F66EF31C54F3D0F63F8D52BFC1B3A4"
361
+ }
362
+ eos
363
+ end
364
+
365
+
257
366
  def bank_account_array_response
258
367
  <<-eos
259
368
  {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slidepay
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Rothstein
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-25 00:00:00.000000000 Z
11
+ date: 2013-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -165,6 +165,8 @@ files:
165
165
  - lib/slidepay/util.rb
166
166
  - lib/slidepay/version.rb
167
167
  - scenarios/example.rb
168
+ - scenarios/payment_find_where_id.rb
169
+ - scenarios/payment_find_where_under_review.rb
168
170
  - slidepay.gemspec
169
171
  - spec/api_key_spec.rb
170
172
  - spec/api_resource_spec.rb