twocheckout 0.1.4 → 0.2.0
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/README.md +88 -2
- data/lib/twocheckout.rb +0 -0
- data/lib/twocheckout/api.rb +53 -20
- data/lib/twocheckout/checkout.rb +6 -1
- data/lib/twocheckout/company.rb +0 -0
- data/lib/twocheckout/coupon.rb +0 -0
- data/lib/twocheckout/hash_object.rb +0 -0
- data/lib/twocheckout/invoice.rb +0 -0
- data/lib/twocheckout/lineitem.rb +0 -0
- data/lib/twocheckout/option.rb +0 -0
- data/lib/twocheckout/product.rb +0 -0
- data/lib/twocheckout/sale.rb +0 -0
- data/lib/twocheckout/twocheckout_error.rb +0 -0
- data/lib/twocheckout/validate_response.rb +0 -0
- data/lib/twocheckout/version.rb +1 -1
- data/test/minitest_helper.rb +6 -1
- data/test/twocheckout_test.rb +26 -0
- data/twocheckout.gemspec +3 -3
- metadata +9 -7
- data/twocheckout-0.1.3.gem +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f1626c1aac085f25b351a2be715c38ea80e0d9fd
|
4
|
+
data.tar.gz: c14dcf32498ac74d878f9712b6f3980035b42b4f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f19c9b26078b7d32186394c81ebed1cfb6cbbfbef1ddcb5d73961f6f989a9e1497cf3bd860314100397bb01bcb1d08b61a24fa1158db9f20a9e7a529e04369be
|
7
|
+
data.tar.gz: 232c8710c4b54d3a54acaadbef77e972cc35cba9895566739a2977d738c7aa93a2b57d4a5bae20f791196ee22dc39c24677068f5ef9b26b5e1d44ae5938015a0
|
data/README.md
CHANGED
@@ -12,13 +12,99 @@ gem install twocheckout
|
|
12
12
|
Or import into your Gemfile.
|
13
13
|
|
14
14
|
```ruby
|
15
|
-
gem "twocheckout"
|
15
|
+
gem "twocheckout"
|
16
16
|
```
|
17
17
|
|
18
18
|
Full documentation for each binding is provided in the **[Wiki](https://github.com/2checkout/2checkout-ruby/wiki)**.
|
19
19
|
|
20
20
|
|
21
|
-
Example API Usage
|
21
|
+
Example Purchase API Usage
|
22
|
+
-----------------
|
23
|
+
|
24
|
+
*Example Usage:*
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
Twocheckout::API.credentials = {
|
28
|
+
:seller_id => '1817037',
|
29
|
+
:private_key => '3508079E-5383-44D4-BF69-DC619C0D9811'
|
30
|
+
}
|
31
|
+
|
32
|
+
params = {
|
33
|
+
:merchantOrderId => '123',
|
34
|
+
:token => 'ZmYyMzMyZGMtZTY2NS00NDAxLTlhYTQtMTgwZWIyZTgwMzQx',
|
35
|
+
:currency => 'USD',
|
36
|
+
:total => '1.00',
|
37
|
+
:billingAddr => {
|
38
|
+
:name => 'Testing Tester',
|
39
|
+
:addrLine1 => '123 Test St',
|
40
|
+
:city => 'Columbus',
|
41
|
+
:state => 'OH',
|
42
|
+
:zipCode => '43123',
|
43
|
+
:country => 'USA',
|
44
|
+
:email => 'cchristenson@2co.com',
|
45
|
+
:phoneNumber => '555-555-5555'
|
46
|
+
}
|
47
|
+
}
|
48
|
+
|
49
|
+
begin
|
50
|
+
result = Twocheckout::Checkout.authorize(params)
|
51
|
+
rescue Exception => e
|
52
|
+
puts e.message
|
53
|
+
end
|
54
|
+
```
|
55
|
+
|
56
|
+
*Example Response:*
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
#<Twocheckout::Checkout>{
|
60
|
+
"type"=>"AuthResponse",
|
61
|
+
"lineItems"=>
|
62
|
+
[{"options"=>[],
|
63
|
+
"price"=>"1.00",
|
64
|
+
"quantity"=>"1",
|
65
|
+
"recurrence"=>nil,
|
66
|
+
"startupFee"=>nil,
|
67
|
+
"productId"=>"",
|
68
|
+
"tangible"=>"N",
|
69
|
+
"name"=>"123",
|
70
|
+
"type"=>"product",
|
71
|
+
"description"=>"",
|
72
|
+
"duration"=>nil}],
|
73
|
+
"transactionId"=>"205180760223",
|
74
|
+
"billingAddr"=>
|
75
|
+
{"addrLine1"=>"123 Test St",
|
76
|
+
"addrLine2"=>nil,
|
77
|
+
"city"=>"Columbus",
|
78
|
+
"zipCode"=>"43123",
|
79
|
+
"phoneNumber"=>"555-555-5555",
|
80
|
+
"phoneExtension"=>nil,
|
81
|
+
"email"=>"cchristenson@2co.com",
|
82
|
+
"name"=>"Testing Tester",
|
83
|
+
"state"=>"OH",
|
84
|
+
"country"=>"USA"},
|
85
|
+
"shippingAddr"=>
|
86
|
+
{"addrLine1"=>nil,
|
87
|
+
"addrLine2"=>nil,
|
88
|
+
"city"=>nil,
|
89
|
+
"zipCode"=>nil,
|
90
|
+
"phoneNumber"=>nil,
|
91
|
+
"phoneExtension"=>nil,
|
92
|
+
"email"=>nil,
|
93
|
+
"name"=>nil,
|
94
|
+
"state"=>nil,
|
95
|
+
"country"=>nil},
|
96
|
+
"merchantOrderId"=>"123",
|
97
|
+
"orderNumber"=>"205180760214",
|
98
|
+
"recurrentInstallmentId"=>nil,
|
99
|
+
"responseMsg"=>"Successfully authorized the provided credit card",
|
100
|
+
"responseCode"=>"APPROVED",
|
101
|
+
"total"=>"1.00",
|
102
|
+
"currencyCode"=>"USD",
|
103
|
+
"errors"=>nil}
|
104
|
+
```
|
105
|
+
|
106
|
+
|
107
|
+
Example Admin API Usage
|
22
108
|
-----------------
|
23
109
|
|
24
110
|
*Example Usage:*
|
data/lib/twocheckout.rb
CHANGED
File without changes
|
data/lib/twocheckout/api.rb
CHANGED
@@ -4,46 +4,79 @@ require 'json'
|
|
4
4
|
module Twocheckout
|
5
5
|
class API
|
6
6
|
API_BASE = 'https://www.2checkout.com/api/'
|
7
|
+
CHECKOUT_BASE = 'https://www.2checkout.com/checkout/api/'
|
8
|
+
SANDBOX_BASE = 'https://sandbox.2checkout.com/checkout/api/'
|
9
|
+
API_VERSION = '1'
|
7
10
|
|
8
11
|
def self.credentials=(opts)
|
9
12
|
@@username = opts[:username]
|
10
13
|
@@password = opts[:password]
|
11
|
-
opts
|
14
|
+
@@private_key = opts[:private_key]
|
15
|
+
@@seller_id = opts[:seller_id]
|
16
|
+
@@sandbox = opts[:sandbox]
|
12
17
|
end
|
13
18
|
|
14
19
|
def self.request(http_method, api_call, params = nil)
|
15
|
-
|
16
|
-
if http_method == :get
|
17
|
-
url += hash_to_querystring(params)
|
18
|
-
params = nil
|
19
|
-
end
|
20
|
-
opts = {
|
21
|
-
:method => http_method,
|
22
|
-
:url => url,
|
23
|
-
:headers => {
|
24
|
-
:accept => :json,
|
25
|
-
:content_type => :json,
|
26
|
-
:user_agent => "2Checkout/Ruby/," + Twocheckout::VERSION
|
27
|
-
},
|
28
|
-
:user => @@username,
|
29
|
-
:password => @@password,
|
30
|
-
:payload => params,
|
31
|
-
}
|
20
|
+
opts = set_opts(http_method, api_call, params)
|
32
21
|
begin
|
33
22
|
response = RestClient::Request.execute(opts)
|
34
23
|
JSON.parse(response)
|
35
24
|
rescue => e
|
36
25
|
error_hash = JSON.parse(e.response)
|
37
|
-
|
26
|
+
if error_hash['exception']
|
27
|
+
raise TwocheckoutError.new(error_hash['exception']['errorMsg']).retrieve
|
28
|
+
else
|
29
|
+
raise TwocheckoutError.new(error_hash['errors'][0]['message']).retrieve
|
30
|
+
end
|
38
31
|
end
|
39
32
|
end
|
40
33
|
|
41
34
|
private
|
42
35
|
|
36
|
+
def self.set_opts(http_method, api_call, params = null)
|
37
|
+
if api_call == 'authService'
|
38
|
+
url = @@sandbox? SANDBOX_BASE : CHECKOUT_BASE
|
39
|
+
url += API_VERSION + '/' + @@seller_id + '/rs/' + api_call
|
40
|
+
params['sellerId'] = @@seller_id
|
41
|
+
params['privateKey'] = @@private_key
|
42
|
+
opts = {
|
43
|
+
:method => http_method,
|
44
|
+
:url => url,
|
45
|
+
:headers => {
|
46
|
+
:accept => :json,
|
47
|
+
:content_type => :json,
|
48
|
+
:user_agent => "2Checkout/Ruby/," + Twocheckout::VERSION
|
49
|
+
},
|
50
|
+
:payload => params.to_json,
|
51
|
+
}
|
52
|
+
else
|
53
|
+
url = API_BASE + api_call
|
54
|
+
if http_method == :get
|
55
|
+
url += hash_to_querystring(params)
|
56
|
+
params = nil
|
57
|
+
end
|
58
|
+
|
59
|
+
opts = {
|
60
|
+
:method => http_method,
|
61
|
+
:url => url,
|
62
|
+
:headers => {
|
63
|
+
:accept => :json,
|
64
|
+
:content_type => :json,
|
65
|
+
:user_agent => "2Checkout/Ruby/," + Twocheckout::VERSION
|
66
|
+
},
|
67
|
+
:user => @@username,
|
68
|
+
:password => @@password,
|
69
|
+
:payload => params,
|
70
|
+
}
|
71
|
+
end
|
72
|
+
|
73
|
+
return opts
|
74
|
+
end
|
75
|
+
|
43
76
|
def self.hash_to_querystring(hash)
|
44
77
|
return '' if hash.nil? || hash.empty?
|
45
78
|
'?' + hash.map { |k,v| "#{URI.encode(k.to_s)}=#{URI.encode(v.to_s)}" }.join('&')
|
46
79
|
end
|
47
80
|
|
48
81
|
end
|
49
|
-
end
|
82
|
+
end
|
data/lib/twocheckout/checkout.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module Twocheckout
|
2
|
-
class Checkout
|
2
|
+
class Checkout < HashObject
|
3
3
|
|
4
4
|
def self.form(params={}, button_text='Proceed to Checkout')
|
5
5
|
@form = "<form id=\"2checkout\" action=\"https://www.2checkout.com/checkout/purchase\" method=\"post\">\n";
|
@@ -31,5 +31,10 @@ module Twocheckout
|
|
31
31
|
@querystring = params.map{|k,v| "#{CGI.escape(k)}=#{CGI.escape(v)}"}.join("&")
|
32
32
|
@purchase_url = url + @querystring
|
33
33
|
end
|
34
|
+
|
35
|
+
def self.authorize(params={})
|
36
|
+
response = Twocheckout::API.request(:post, 'authService', params)
|
37
|
+
response['response']
|
38
|
+
end
|
34
39
|
end
|
35
40
|
end
|
data/lib/twocheckout/company.rb
CHANGED
File without changes
|
data/lib/twocheckout/coupon.rb
CHANGED
File without changes
|
File without changes
|
data/lib/twocheckout/invoice.rb
CHANGED
File without changes
|
data/lib/twocheckout/lineitem.rb
CHANGED
File without changes
|
data/lib/twocheckout/option.rb
CHANGED
File without changes
|
data/lib/twocheckout/product.rb
CHANGED
File without changes
|
data/lib/twocheckout/sale.rb
CHANGED
File without changes
|
File without changes
|
File without changes
|
data/lib/twocheckout/version.rb
CHANGED
data/test/minitest_helper.rb
CHANGED
@@ -2,4 +2,9 @@ require "minitest/spec"
|
|
2
2
|
require "minitest/autorun"
|
3
3
|
require "twocheckout"
|
4
4
|
|
5
|
-
Twocheckout::API.credentials = {
|
5
|
+
Twocheckout::API.credentials = {
|
6
|
+
:username => 'APIuser1817037',
|
7
|
+
:password => 'APIpass1817037',
|
8
|
+
:seller_id => '532001',
|
9
|
+
:private_key => '9999999'
|
10
|
+
}
|
data/test/twocheckout_test.rb
CHANGED
@@ -272,4 +272,30 @@ describe Twocheckout::Checkout do
|
|
272
272
|
@link = "https://www.2checkout.com/checkout/purchase?sid=1817037&cart_order_id=Example+Sale&total=1.00"
|
273
273
|
assert_equal(link, @link)
|
274
274
|
end
|
275
|
+
|
276
|
+
#authorize
|
277
|
+
it "Authorize creates authorization" do
|
278
|
+
params = {
|
279
|
+
:merchantOrderId => '123',
|
280
|
+
:token => 'ZThjM2U3ZjMtMjViYy00ZTAwLWJiY2MtMDgzNTEzODZhZTFh',
|
281
|
+
:currency => 'USD',
|
282
|
+
:total => '1.00',
|
283
|
+
:billingAddr => {
|
284
|
+
:name => 'Testing Tester',
|
285
|
+
:addrLine1 => '123 Test St',
|
286
|
+
:city => 'Columbus',
|
287
|
+
:state => 'OH',
|
288
|
+
:zipCode => '43123',
|
289
|
+
:country => 'USA',
|
290
|
+
:email => 'cchristenson@2co.com',
|
291
|
+
:phoneNumber => '555-555-5555'
|
292
|
+
}
|
293
|
+
}
|
294
|
+
begin
|
295
|
+
result = Twocheckout::Checkout.authorize(params)
|
296
|
+
assert_equal("APPROVED", result['responseCode'])
|
297
|
+
rescue Exception => e
|
298
|
+
assert_equal("Unauthorized", e.message)
|
299
|
+
end
|
300
|
+
end
|
275
301
|
end
|
data/twocheckout.gemspec
CHANGED
@@ -4,9 +4,9 @@ $:.unshift(File.join(File.dirname(__FILE__), 'lib'))
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.platform = Gem::Platform::RUBY
|
6
6
|
s.name = 'twocheckout'
|
7
|
-
s.version = '0.
|
7
|
+
s.version = '0.2.0'
|
8
8
|
s.summary = '2Checkout Ruby Library'
|
9
|
-
s.description = '0.
|
9
|
+
s.description = '0.2.0'
|
10
10
|
s.summary = '2Checkout Ruby Library'
|
11
11
|
s.author = "Craig Christenson", "Ernesto Garcia"
|
12
12
|
s.email = 'christensoncraig@gmail.com'
|
@@ -17,5 +17,5 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.add_dependency('rest-client', '~> 1.4')
|
18
18
|
s.require_paths = %w{lib}
|
19
19
|
s.requirements << 'none'
|
20
|
-
|
20
|
+
s.license = 'MIT'
|
21
21
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twocheckout
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Craig Christenson
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-01-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|
@@ -25,7 +25,7 @@ dependencies:
|
|
25
25
|
- - ~>
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: '1.4'
|
28
|
-
description: 0.
|
28
|
+
description: 0.2.0
|
29
29
|
email: christensoncraig@gmail.com
|
30
30
|
executables: []
|
31
31
|
extensions: []
|
@@ -50,10 +50,10 @@ files:
|
|
50
50
|
- lib/twocheckout/version.rb
|
51
51
|
- test/minitest_helper.rb
|
52
52
|
- test/twocheckout_test.rb
|
53
|
-
- twocheckout-0.1.3.gem
|
54
53
|
- twocheckout.gemspec
|
55
54
|
homepage: https://github.com/craigchristenson
|
56
|
-
licenses:
|
55
|
+
licenses:
|
56
|
+
- MIT
|
57
57
|
metadata: {}
|
58
58
|
post_install_message:
|
59
59
|
rdoc_options: []
|
@@ -72,8 +72,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
72
72
|
requirements:
|
73
73
|
- none
|
74
74
|
rubyforge_project:
|
75
|
-
rubygems_version: 2.
|
75
|
+
rubygems_version: 2.2.1
|
76
76
|
signing_key:
|
77
77
|
specification_version: 4
|
78
78
|
summary: 2Checkout Ruby Library
|
79
|
-
test_files:
|
79
|
+
test_files:
|
80
|
+
- test/minitest_helper.rb
|
81
|
+
- test/twocheckout_test.rb
|
data/twocheckout-0.1.3.gem
DELETED
Binary file
|