twocheckout 0.1.4 → 0.5.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 +5 -5
- data/README.md +90 -4
- data/lib/twocheckout.rb +11 -13
- data/lib/twocheckout/api.rb +53 -23
- data/lib/twocheckout/checkout.rb +13 -6
- data/lib/twocheckout/sale.rb +0 -7
- data/lib/twocheckout/twocheckout_error.rb +4 -11
- data/lib/twocheckout/version.rb +1 -1
- data/test/minitest_helper.rb +6 -2
- data/test/twocheckout_test.rb +117 -152
- data/twocheckout.gemspec +7 -7
- metadata +17 -17
- data/lib/twocheckout/coupon.rb +0 -41
- data/lib/twocheckout/option.rb +0 -57
- data/twocheckout-0.1.3.gem +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6ae819e29f87aa59ae4f4756f06d8e1cdccba403f504f4e2eafd5e3e86ef64c3
|
4
|
+
data.tar.gz: dbe2d6eb71fb17e18d37585f2183976225f1da6d3849d09834f1a727cc4304fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9957625ac830b0e2b4be232e449dd29cb9bed844526a943a3aacc0bed878eb0f5eea1b9b95329c7a10d23ca963e486d173d2801ffb623e1855c47bb6579d9f02
|
7
|
+
data.tar.gz: 7001057a88943e0c38900c38893bef7e1b9638768285a71848f240381b9c1ed6492e75df4680a5273297026d665cd60d6d550e497bca4b249ccc42412856467c
|
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
|
-
Full documentation for each binding is provided in the **[
|
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:*
|
@@ -198,4 +284,4 @@ end
|
|
198
284
|
"Lineitem is not scheduled to recur."
|
199
285
|
```
|
200
286
|
|
201
|
-
Full documentation for each binding is provided in the **[
|
287
|
+
Full documentation for each binding is provided in the **[wiki](https://github.com/2Checkout/2checkout-ruby/wiki)**.
|
data/lib/twocheckout.rb
CHANGED
@@ -1,13 +1,11 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require "twocheckout/checkout"
|
13
|
-
require "twocheckout/twocheckout_error"
|
1
|
+
require 'twocheckout/version'
|
2
|
+
require 'twocheckout/api'
|
3
|
+
require 'twocheckout/hash_object'
|
4
|
+
require 'twocheckout/validate_response'
|
5
|
+
require 'twocheckout/company'
|
6
|
+
require 'twocheckout/lineitem'
|
7
|
+
require 'twocheckout/invoice'
|
8
|
+
require 'twocheckout/sale'
|
9
|
+
require 'twocheckout/product'
|
10
|
+
require 'twocheckout/checkout'
|
11
|
+
require 'twocheckout/twocheckout_error'
|
data/lib/twocheckout/api.rb
CHANGED
@@ -3,47 +3,77 @@ require 'json'
|
|
3
3
|
|
4
4
|
module Twocheckout
|
5
5
|
class API
|
6
|
-
|
6
|
+
PROD_BASE = 'https://www.2checkout.com'.freeze
|
7
|
+
API_VERSION = '1'.freeze
|
7
8
|
|
8
9
|
def self.credentials=(opts)
|
9
|
-
|
10
|
-
|
11
|
-
opts
|
10
|
+
@username = opts[:username]
|
11
|
+
@password = opts[:password]
|
12
|
+
@private_key = opts[:private_key]
|
13
|
+
@seller_id = opts[:seller_id]
|
12
14
|
end
|
13
15
|
|
14
16
|
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
|
-
}
|
17
|
+
opts = set_opts(http_method, api_call, params)
|
32
18
|
begin
|
33
19
|
response = RestClient::Request.execute(opts)
|
34
20
|
JSON.parse(response)
|
35
21
|
rescue => e
|
36
22
|
error_hash = JSON.parse(e.response)
|
37
|
-
|
23
|
+
if error_hash['exception']
|
24
|
+
raise TwocheckoutError.new(error_hash['exception']['errorMsg'], error_hash['exception']['errorCode'])
|
25
|
+
else
|
26
|
+
raise TwocheckoutError.new(error_hash['errors'][0]['message'])
|
27
|
+
end
|
38
28
|
end
|
39
29
|
end
|
40
30
|
|
41
31
|
private
|
42
32
|
|
33
|
+
def self.set_opts(http_method, api_call, params = null)
|
34
|
+
url = PROD_BASE
|
35
|
+
if api_call == 'authService'
|
36
|
+
url += '/checkout/api/' + API_VERSION + '/' + @seller_id + '/rs/' + api_call
|
37
|
+
params['sellerId'] = @seller_id
|
38
|
+
params['privateKey'] = @private_key
|
39
|
+
opts = {
|
40
|
+
:method => http_method,
|
41
|
+
:url => url,
|
42
|
+
:headers => {
|
43
|
+
:accept => :json,
|
44
|
+
:content_type => :json,
|
45
|
+
:user_agent => "2Checkout/Ruby/," + Twocheckout::VERSION
|
46
|
+
},
|
47
|
+
:payload => params.to_json,
|
48
|
+
}
|
49
|
+
else
|
50
|
+
url += '/api/' + api_call
|
51
|
+
if http_method == :get
|
52
|
+
url += hash_to_querystring(params)
|
53
|
+
params = nil
|
54
|
+
end
|
55
|
+
|
56
|
+
opts = {
|
57
|
+
:method => http_method,
|
58
|
+
:url => url,
|
59
|
+
:headers => {
|
60
|
+
:accept => :json,
|
61
|
+
:content_type => :json,
|
62
|
+
:user_agent => "2Checkout/Ruby/," + Twocheckout::VERSION
|
63
|
+
},
|
64
|
+
:user => @username,
|
65
|
+
:password => @password,
|
66
|
+
:payload => params,
|
67
|
+
}
|
68
|
+
end
|
69
|
+
|
70
|
+
return opts
|
71
|
+
end
|
72
|
+
|
43
73
|
def self.hash_to_querystring(hash)
|
44
74
|
return '' if hash.nil? || hash.empty?
|
45
75
|
'?' + hash.map { |k,v| "#{URI.encode(k.to_s)}=#{URI.encode(v.to_s)}" }.join('&')
|
46
76
|
end
|
47
77
|
|
48
78
|
end
|
49
|
-
end
|
79
|
+
end
|
data/lib/twocheckout/checkout.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
module Twocheckout
|
2
|
-
class Checkout
|
2
|
+
class Checkout < HashObject
|
3
|
+
|
4
|
+
@checkout_url = 'https://www.2checkout.com/checkout/purchase'
|
3
5
|
|
4
6
|
def self.form(params={}, button_text='Proceed to Checkout')
|
5
|
-
@form = "<form id=\"2checkout\" action=\"
|
7
|
+
@form = "<form id=\"2checkout\" action=\"#{@checkout_url}\" method=\"post\">\n";
|
6
8
|
params.each do |k,v|
|
7
9
|
@form = @form + "<input type=\"hidden\" name=\"" + k + "\" value=\"" + v.to_s + "\" />\n"
|
8
10
|
end
|
@@ -10,7 +12,7 @@ module Twocheckout
|
|
10
12
|
end
|
11
13
|
|
12
14
|
def self.submit(params={})
|
13
|
-
@form = "<form id=\"2checkout\" action=\"
|
15
|
+
@form = "<form id=\"2checkout\" action=\"#{@checkout_url}\" method=\"post\">\n";
|
14
16
|
params.each do |k,v|
|
15
17
|
@form = @form + "<input type=\"hidden\" name=\"" + k + "\" value=\"" + v.to_s + "\" />\n"
|
16
18
|
end
|
@@ -19,7 +21,7 @@ module Twocheckout
|
|
19
21
|
end
|
20
22
|
|
21
23
|
def self.direct(params={}, button_text='Proceed to Checkout')
|
22
|
-
@form = "<form id=\"2checkout\" action=\"
|
24
|
+
@form = "<form id=\"2checkout\" action=\"#{@checkout_url}\" method=\"post\">\n";
|
23
25
|
params.each do |k,v|
|
24
26
|
@form = @form + "<input type=\"hidden\" name=\"" + k + "\" value=\"" + v.to_s + "\" />\n"
|
25
27
|
end
|
@@ -27,9 +29,14 @@ module Twocheckout
|
|
27
29
|
@form = @form + "<script src=\"https://www.2checkout.com/static/checkout/javascript/direct.min.js\"></script>"
|
28
30
|
end
|
29
31
|
|
30
|
-
def self.link(params={}
|
32
|
+
def self.link(params={})
|
31
33
|
@querystring = params.map{|k,v| "#{CGI.escape(k)}=#{CGI.escape(v)}"}.join("&")
|
32
|
-
@purchase_url =
|
34
|
+
@purchase_url = @checkout_url + '?' + @querystring
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.authorize(params={})
|
38
|
+
response = Twocheckout::API.request(:post, 'authService', params)
|
39
|
+
response['response']
|
33
40
|
end
|
34
41
|
end
|
35
42
|
end
|
data/lib/twocheckout/sale.rb
CHANGED
@@ -75,13 +75,6 @@ module Twocheckout
|
|
75
75
|
Twocheckout::API.request(:post, 'sales/mark_shipped', opts)
|
76
76
|
end
|
77
77
|
|
78
|
-
#
|
79
|
-
# Reauthorize sale
|
80
|
-
#
|
81
|
-
def reauth
|
82
|
-
Twocheckout::API.request(:post, 'sales/reauth', sale_id: self.sale_id)
|
83
|
-
end
|
84
|
-
|
85
78
|
#
|
86
79
|
# Get sale list in an array
|
87
80
|
#
|
@@ -1,18 +1,11 @@
|
|
1
1
|
module Twocheckout
|
2
2
|
class TwocheckoutError < StandardError
|
3
3
|
attr_reader :message
|
4
|
+
attr_reader :code
|
4
5
|
|
5
|
-
def initialize(message)
|
6
|
+
def initialize(message, code = nil)
|
6
7
|
@message = message
|
7
|
-
|
8
|
-
|
9
|
-
def retrieve
|
10
|
-
if @message.is_a?(Hash)
|
11
|
-
@message = JSON.generate(@message)
|
12
|
-
"#{@message}"
|
13
|
-
else
|
14
|
-
"#{@message}"
|
15
|
-
end
|
8
|
+
@code = code
|
16
9
|
end
|
17
10
|
end
|
18
|
-
end
|
11
|
+
end
|
data/lib/twocheckout/version.rb
CHANGED
data/test/minitest_helper.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
|
-
require "minitest/spec"
|
2
1
|
require "minitest/autorun"
|
3
2
|
require "twocheckout"
|
4
3
|
|
5
|
-
Twocheckout::API.credentials = {
|
4
|
+
Twocheckout::API.credentials = {
|
5
|
+
:username => 'CREDENTIALS HERE',
|
6
|
+
:password => 'CREDENTIALS HERE',
|
7
|
+
:seller_id => 'CREDENTIALS HERE',
|
8
|
+
:private_key => 'CREDENTIALS HERE',
|
9
|
+
}
|
data/test/twocheckout_test.rb
CHANGED
@@ -7,14 +7,14 @@ describe Twocheckout::Sale do
|
|
7
7
|
|
8
8
|
#retrieve sale
|
9
9
|
it "Sale retrieve returns sale" do
|
10
|
-
sale = Twocheckout::Sale.find(:sale_id =>
|
11
|
-
assert_equal('
|
10
|
+
sale = Twocheckout::Sale.find(:sale_id => 250335346812)
|
11
|
+
assert_equal('250335346812', sale.sale_id)
|
12
12
|
end
|
13
13
|
|
14
14
|
#retrieve invoice
|
15
15
|
it "Sale retrieve returns invoice" do
|
16
|
-
invoice = Twocheckout::Sale.find({:invoice_id =>
|
17
|
-
assert_equal('
|
16
|
+
invoice = Twocheckout::Sale.find({:invoice_id => 250334725631})
|
17
|
+
assert_equal('250334725631', invoice.invoice_id)
|
18
18
|
end
|
19
19
|
|
20
20
|
#retrieve sale list
|
@@ -24,85 +24,75 @@ describe Twocheckout::Sale do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
#refund sale
|
27
|
-
it "Refunding a refunded sale returns
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
rescue
|
32
|
-
|
27
|
+
it "Refunding a refunded sale returns Twocheckout::TwocheckoutError" do
|
28
|
+
begin
|
29
|
+
sale = Twocheckout::Sale.find(:sale_id => 250335365202)
|
30
|
+
sale.refund!({:comment => "test refund", :category => 1})
|
31
|
+
rescue Twocheckout::TwocheckoutError => e
|
32
|
+
assert_equal("Amount greater than remaining balance on invoice.", e.message)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
36
|
#refund invoice
|
37
|
-
it "Refunding a refunded invoice returns
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
rescue
|
43
|
-
|
37
|
+
it "Refunding a refunded invoice returns Twocheckout::TwocheckoutError" do
|
38
|
+
begin
|
39
|
+
sale = Twocheckout::Sale.find(:sale_id => 250335365202)
|
40
|
+
invoice = sale.invoices.first
|
41
|
+
invoice.refund!({:comment => "test refund", :category => 1})
|
42
|
+
rescue Twocheckout::TwocheckoutError => e
|
43
|
+
assert_equal("Amount greater than remaining balance on invoice.", e.message)
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
47
|
#refund lineitem
|
48
|
-
it "Refunding a refunded lineitem returns
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
rescue
|
55
|
-
|
48
|
+
it "Refunding a refunded lineitem returns Twocheckout::TwocheckoutError" do
|
49
|
+
begin
|
50
|
+
sale = Twocheckout::Sale.find(:sale_id => 250192108517)
|
51
|
+
first_invoice = sale.invoices.first
|
52
|
+
last_lineitem = first_invoice.lineitems.last
|
53
|
+
last_lineitem.refund!({:comment => "test refund", :category => 1})
|
54
|
+
rescue Twocheckout::TwocheckoutError => e
|
55
|
+
assert_equal("Lineitem amount greater than remaining balance on invoice.", e.message)
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
59
|
#stop recurring lineitem
|
60
|
-
it "Stopping a stopped recurring lineitem returns
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
rescue
|
66
|
-
|
60
|
+
it "Stopping a stopped recurring lineitem returns Twocheckout::TwocheckoutError" do
|
61
|
+
begin
|
62
|
+
sale = Twocheckout::Sale.find(:sale_id => 250192108517)
|
63
|
+
result = sale.stop_recurring!
|
64
|
+
assert_equal(result, [])
|
65
|
+
rescue Twocheckout::TwocheckoutError => e
|
66
|
+
assert_equal("Lineitem is not scheduled to recur.", e.message)
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
70
|
#stop recurring sale
|
71
|
-
it "Stopping a stopped recurring sale returns
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
rescue
|
78
|
-
|
71
|
+
it "Stopping a stopped recurring sale returns Twocheckout::TwocheckoutError" do
|
72
|
+
begin
|
73
|
+
sale = Twocheckout::Sale.find(:sale_id => 250192108517)
|
74
|
+
last_invoice = sale.invoices.last
|
75
|
+
last_lineitem = last_invoice.lineitems.last
|
76
|
+
last_lineitem.stop_recurring!
|
77
|
+
rescue Twocheckout::TwocheckoutError => e
|
78
|
+
assert_equal("Lineitem is not scheduled to recur.", e.message)
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
82
|
#create comment
|
83
83
|
it "Creates a sale comment" do
|
84
|
-
|
84
|
+
sale = Twocheckout::Sale.find(:sale_id => 250334624367)
|
85
85
|
result = sale.comment({:sale_comment => "test"})
|
86
86
|
assert_equal('Created comment successfully.', result['response_message'])
|
87
87
|
end
|
88
88
|
|
89
89
|
#mark shipped
|
90
|
-
it "Shipping an intangible sale returns
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
rescue
|
95
|
-
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
#reauth
|
100
|
-
it "Reauthorizing a pending sale returns exception" do
|
101
|
-
begin
|
102
|
-
sale = Twocheckout::Sale.find(:sale_id => 4786293822)
|
103
|
-
sale.reauth
|
104
|
-
rescue Exception => e
|
105
|
-
assert_equal("Payment is already pending or deposited and cannot be reauthorized.", e.message)
|
90
|
+
it "Shipping an intangible sale returns Twocheckout::TwocheckoutError" do
|
91
|
+
begin
|
92
|
+
sale = Twocheckout::Sale.find(:sale_id => 250335377097)
|
93
|
+
sale.ship({:tracking_number => "123"})
|
94
|
+
rescue Twocheckout::TwocheckoutError => e
|
95
|
+
assert_equal("Sale already marked shipped.", e.message)
|
106
96
|
end
|
107
97
|
end
|
108
98
|
end
|
@@ -115,98 +105,46 @@ describe Twocheckout::Product do
|
|
115
105
|
|
116
106
|
# Product list
|
117
107
|
it "Product list returns array of products" do
|
118
|
-
product_list = Twocheckout::Product.list({ :pagesize =>
|
119
|
-
|
108
|
+
product_list = Twocheckout::Product.list({ :pagesize => 3 })
|
109
|
+
assert_equal(product_list.size, 3)
|
120
110
|
end
|
121
111
|
|
122
112
|
# Product CRUD
|
123
|
-
|
124
|
-
|
113
|
+
it "Product create, find, update, delete is successful" do
|
114
|
+
# create
|
125
115
|
new_product = Twocheckout::Product.create({:name => "test product", :price => 1.00})
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
describe Twocheckout::Option do
|
140
|
-
|
141
|
-
# Option list
|
142
|
-
it "Option list returns array of options" do
|
143
|
-
option_list = Twocheckout::Option.list({ :pagesize => 5 })
|
144
|
-
assert_equal(5, option_list.size)
|
145
|
-
end
|
146
|
-
|
147
|
-
# Option CRUD
|
148
|
-
it "Option create, find, update, delete is successful" do
|
149
|
-
# create
|
150
|
-
new_option = Twocheckout::Option.create({:option_name => "test option",
|
151
|
-
:option_value_name => "test option value", :option_value_surcharge => 1.00})
|
152
|
-
assert_equal("test option", new_option.option_name)
|
153
|
-
# find
|
154
|
-
option = Twocheckout::Option.find({:option_id => new_option.option_id})
|
155
|
-
assert_equal(new_option.option_id, option.option_id)
|
156
|
-
# update
|
157
|
-
option = option.update({:option_name => "new name"})
|
158
|
-
assert_equal("new name", option.option_name)
|
159
|
-
# delete
|
160
|
-
result = option.delete!
|
161
|
-
assert_equal("Option deleted successfully", result['response_message'])
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
describe Twocheckout::Coupon do
|
166
|
-
|
167
|
-
# Coupon list
|
168
|
-
it "Coupon list returns array of coupons" do
|
169
|
-
coupon_list = Twocheckout::Coupon.list({ :pagesize => 4 })
|
170
|
-
assert_equal(4, coupon_list.size)
|
171
|
-
end
|
172
|
-
|
173
|
-
# Coupon CRUD
|
174
|
-
it "Coupon create, find, update, delete is successful" do
|
175
|
-
# create
|
176
|
-
new_coupon = Twocheckout::Coupon.create({:date_expire => "2020-01-01",
|
177
|
-
:type => "shipping", :minimum_purchase => 1.00})
|
178
|
-
assert_equal("2020-01-01", new_coupon.date_expire)
|
179
|
-
# find
|
180
|
-
coupon = Twocheckout::Coupon.find({:coupon_code => new_coupon.coupon_code})
|
181
|
-
assert_equal(new_coupon.coupon_code, coupon.coupon_code)
|
182
|
-
# update
|
183
|
-
coupon = coupon.update({:date_expire => "2020-01-02"})
|
184
|
-
assert_equal("2020-01-02", coupon.date_expire)
|
185
|
-
# delete
|
186
|
-
result = coupon.delete!
|
187
|
-
assert_equal("Coupon successfully deleted.", result['response_message'])
|
116
|
+
assert_equal("test product", new_product.name)
|
117
|
+
# find
|
118
|
+
product = Twocheckout::Product.find({:product_id => new_product.product_id})
|
119
|
+
assert_equal(new_product.product_id, product.product_id)
|
120
|
+
# update
|
121
|
+
product = product.update({:name => "new name"})
|
122
|
+
assert_equal("new name", product.name)
|
123
|
+
# delete
|
124
|
+
result = product.delete!
|
125
|
+
assert_equal("Product successfully deleted.", result['response_message'])
|
188
126
|
end
|
189
127
|
end
|
190
128
|
|
191
129
|
describe Twocheckout::ValidateResponse do
|
192
|
-
|
130
|
+
|
193
131
|
it "Validates Purchase MD5 Hash" do
|
194
132
|
result = Twocheckout::ValidateResponse.purchase({:sid => 1817037, :secret => "tango", :order_number => 1, :total => 0.01,
|
195
|
-
|
133
|
+
:key => '1BC47EA0D63EB76496E294F434138AD3'})
|
196
134
|
assert_equal('PASS', result[:code])
|
197
135
|
end
|
198
136
|
|
199
137
|
#purchase
|
200
138
|
it "Validates Purchase MD5 Hash" do
|
201
139
|
result = Twocheckout::ValidateResponse.purchase({:sid => 1817037, :secret => "tango", :order_number => 4789848870, :total => 0.01,
|
202
|
-
|
140
|
+
:key => 'CDF3E502AA1597DD4401760783432337'})
|
203
141
|
assert_equal('PASS', result[:code])
|
204
142
|
end
|
205
143
|
|
206
144
|
#notification
|
207
145
|
it "Validates Notification MD5 Hash" do
|
208
146
|
result = Twocheckout::ValidateResponse.notification({:sale_id => 4789848870, :vendor_id => 1817037, :invoice_id => 4789848879, :secret => "tango",
|
209
|
-
|
147
|
+
:md5_hash => '827220324C722873694758F38D8D3624'})
|
210
148
|
assert_equal('PASS', result[:code])
|
211
149
|
end
|
212
150
|
end
|
@@ -216,11 +154,11 @@ describe Twocheckout::Checkout do
|
|
216
154
|
it "Submit return a form + JS to submit" do
|
217
155
|
form = Twocheckout::Checkout.submit({ 'sid' => '1817037', 'cart_order_id' => 'Example Sale', 'total' => '1.00'})
|
218
156
|
@form = "<form id=\"2checkout\" action=\"https://www.2checkout.com/checkout/purchase\" method=\"post\">\n" +
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
157
|
+
"<input type=\"hidden\" name=\"sid\" value=\"1817037\" />\n" +
|
158
|
+
"<input type=\"hidden\" name=\"cart_order_id\" value=\"Example Sale\" />\n" +
|
159
|
+
"<input type=\"hidden\" name=\"total\" value=\"1.00\" />\n" +
|
160
|
+
"</form>\n" +
|
161
|
+
"<script type=\"text/javascript\">document.getElementById('2checkout').submit();</script>"
|
224
162
|
assert_equal(form, @form)
|
225
163
|
end
|
226
164
|
|
@@ -228,11 +166,11 @@ describe Twocheckout::Checkout do
|
|
228
166
|
it "Form returns a form" do
|
229
167
|
form = Twocheckout::Checkout.form({ 'sid' => '1817037', 'cart_order_id' => 'Example Sale', 'total' => '1.00'}, "Proceed")
|
230
168
|
@form = "<form id=\"2checkout\" action=\"https://www.2checkout.com/checkout/purchase\" method=\"post\">\n" +
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
169
|
+
"<input type=\"hidden\" name=\"sid\" value=\"1817037\" />\n" +
|
170
|
+
"<input type=\"hidden\" name=\"cart_order_id\" value=\"Example Sale\" />\n" +
|
171
|
+
"<input type=\"hidden\" name=\"total\" value=\"1.00\" />\n" +
|
172
|
+
"<input type=\"submit\" value=\"Proceed\" />\n" +
|
173
|
+
"</form>"
|
236
174
|
assert_equal(form, @form)
|
237
175
|
end
|
238
176
|
|
@@ -248,21 +186,21 @@ describe Twocheckout::Checkout do
|
|
248
186
|
'zip' => '43123',
|
249
187
|
'country' => 'USA',
|
250
188
|
'email' => 'no-reply@2co.com'
|
251
|
-
|
189
|
+
})
|
252
190
|
@form = "<form id=\"2checkout\" action=\"https://www.2checkout.com/checkout/purchase\" method=\"post\">\n" +
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
191
|
+
"<input type=\"hidden\" name=\"sid\" value=\"1817037\" />\n" +
|
192
|
+
"<input type=\"hidden\" name=\"cart_order_id\" value=\"Example Sale\" />\n" +
|
193
|
+
"<input type=\"hidden\" name=\"total\" value=\"1.00\" />\n" +
|
194
|
+
"<input type=\"hidden\" name=\"card_holder_name\" value=\"Testing Tester\" />\n" +
|
195
|
+
"<input type=\"hidden\" name=\"street_address\" value=\"123 Test St\" />\n" +
|
196
|
+
"<input type=\"hidden\" name=\"city\" value=\"Columbus\" />\n" +
|
197
|
+
"<input type=\"hidden\" name=\"state\" value=\"Ohio\" />\n" +
|
198
|
+
"<input type=\"hidden\" name=\"zip\" value=\"43123\" />\n" +
|
199
|
+
"<input type=\"hidden\" name=\"country\" value=\"USA\" />\n" +
|
200
|
+
"<input type=\"hidden\" name=\"email\" value=\"no-reply@2co.com\" />\n" +
|
201
|
+
"<input type=\"submit\" value=\"Proceed to Checkout\" />\n" +
|
202
|
+
"</form>\n" +
|
203
|
+
"<script src=\"https://www.2checkout.com/static/checkout/javascript/direct.min.js\"></script>"
|
266
204
|
assert_equal(form, @form)
|
267
205
|
end
|
268
206
|
|
@@ -272,4 +210,31 @@ describe Twocheckout::Checkout do
|
|
272
210
|
@link = "https://www.2checkout.com/checkout/purchase?sid=1817037&cart_order_id=Example+Sale&total=1.00"
|
273
211
|
assert_equal(link, @link)
|
274
212
|
end
|
275
|
-
|
213
|
+
|
214
|
+
#authorize
|
215
|
+
it "Authorize creates authorization" do
|
216
|
+
params = {
|
217
|
+
:merchantOrderId => '123',
|
218
|
+
:token => 'OWM5OTAxM2YtNDhiMC00YjMyLTlkNDQtOWQ5MGRlOGExNDE0',
|
219
|
+
:currency => 'USD',
|
220
|
+
:total => '1.00',
|
221
|
+
:demo => true,
|
222
|
+
:billingAddr => {
|
223
|
+
:name => 'John Doe',
|
224
|
+
:addrLine1 => '123 Test St',
|
225
|
+
:city => 'Columbus',
|
226
|
+
:state => 'OH',
|
227
|
+
:zipCode => '43123',
|
228
|
+
:country => 'USA',
|
229
|
+
:email => 'cchristenson@2co.com',
|
230
|
+
:phoneNumber => '555-555-5555'
|
231
|
+
}
|
232
|
+
}
|
233
|
+
begin
|
234
|
+
result = Twocheckout::Checkout.authorize(params)
|
235
|
+
assert_equal("APPROVED", result['responseCode'])
|
236
|
+
rescue Twocheckout::TwocheckoutError => e
|
237
|
+
assert_equal("Unauthorized", e.message)
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end
|
data/twocheckout.gemspec
CHANGED
@@ -4,18 +4,18 @@ $:.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.5.0'
|
8
8
|
s.summary = '2Checkout Ruby Library'
|
9
|
-
s.description = '0.
|
9
|
+
s.description = '0.5.0'
|
10
10
|
s.summary = '2Checkout Ruby Library'
|
11
|
-
s.author = "Craig Christenson", "Ernesto Garcia"
|
12
|
-
s.email = '
|
13
|
-
s.homepage = 'https://github.com/
|
11
|
+
s.author = "Craig Christenson", "Ernesto Garcia", "Andrei Popa"
|
12
|
+
s.email = 'supportplus@2checkout.com'
|
13
|
+
s.homepage = 'https://github.com/2Checkout/2checkout-ruby'
|
14
14
|
s.files = `git ls-files`.split("\n")
|
15
15
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
16
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
-
s.add_dependency('rest-client', '
|
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,48 +1,47 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twocheckout
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Craig Christenson
|
8
8
|
- Ernesto Garcia
|
9
|
+
- Andrei Popa
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date:
|
13
|
+
date: 2020-06-01 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: rest-client
|
16
17
|
requirement: !ruby/object:Gem::Requirement
|
17
18
|
requirements:
|
18
|
-
- -
|
19
|
+
- - ">="
|
19
20
|
- !ruby/object:Gem::Version
|
20
21
|
version: '1.4'
|
21
22
|
type: :runtime
|
22
23
|
prerelease: false
|
23
24
|
version_requirements: !ruby/object:Gem::Requirement
|
24
25
|
requirements:
|
25
|
-
- -
|
26
|
+
- - ">="
|
26
27
|
- !ruby/object:Gem::Version
|
27
28
|
version: '1.4'
|
28
|
-
description: 0.
|
29
|
-
email:
|
29
|
+
description: 0.5.0
|
30
|
+
email: supportplus@2checkout.com
|
30
31
|
executables: []
|
31
32
|
extensions: []
|
32
33
|
extra_rdoc_files: []
|
33
34
|
files:
|
34
|
-
- .gitignore
|
35
|
+
- ".gitignore"
|
35
36
|
- LICENSE
|
36
37
|
- README.md
|
37
38
|
- lib/twocheckout.rb
|
38
39
|
- lib/twocheckout/api.rb
|
39
40
|
- lib/twocheckout/checkout.rb
|
40
41
|
- lib/twocheckout/company.rb
|
41
|
-
- lib/twocheckout/coupon.rb
|
42
42
|
- lib/twocheckout/hash_object.rb
|
43
43
|
- lib/twocheckout/invoice.rb
|
44
44
|
- lib/twocheckout/lineitem.rb
|
45
|
-
- lib/twocheckout/option.rb
|
46
45
|
- lib/twocheckout/product.rb
|
47
46
|
- lib/twocheckout/sale.rb
|
48
47
|
- lib/twocheckout/twocheckout_error.rb
|
@@ -50,10 +49,10 @@ files:
|
|
50
49
|
- lib/twocheckout/version.rb
|
51
50
|
- test/minitest_helper.rb
|
52
51
|
- test/twocheckout_test.rb
|
53
|
-
- twocheckout-0.1.3.gem
|
54
52
|
- twocheckout.gemspec
|
55
|
-
homepage: https://github.com/
|
56
|
-
licenses:
|
53
|
+
homepage: https://github.com/2Checkout/2checkout-ruby
|
54
|
+
licenses:
|
55
|
+
- MIT
|
57
56
|
metadata: {}
|
58
57
|
post_install_message:
|
59
58
|
rdoc_options: []
|
@@ -61,19 +60,20 @@ require_paths:
|
|
61
60
|
- lib
|
62
61
|
required_ruby_version: !ruby/object:Gem::Requirement
|
63
62
|
requirements:
|
64
|
-
- -
|
63
|
+
- - ">="
|
65
64
|
- !ruby/object:Gem::Version
|
66
65
|
version: '0'
|
67
66
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
67
|
requirements:
|
69
|
-
- -
|
68
|
+
- - ">="
|
70
69
|
- !ruby/object:Gem::Version
|
71
70
|
version: '0'
|
72
71
|
requirements:
|
73
72
|
- none
|
74
|
-
|
75
|
-
rubygems_version: 2.0.3
|
73
|
+
rubygems_version: 3.0.3
|
76
74
|
signing_key:
|
77
75
|
specification_version: 4
|
78
76
|
summary: 2Checkout Ruby Library
|
79
|
-
test_files:
|
77
|
+
test_files:
|
78
|
+
- test/minitest_helper.rb
|
79
|
+
- test/twocheckout_test.rb
|
data/lib/twocheckout/coupon.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
module Twocheckout
|
2
|
-
class Coupon < HashObject
|
3
|
-
|
4
|
-
def self.find(options)
|
5
|
-
response = Twocheckout::API.request(:get, 'products/detail_coupon', options)
|
6
|
-
Coupon.new(response['coupon'])
|
7
|
-
end
|
8
|
-
|
9
|
-
def self.with_coupon_code(coupon_code)
|
10
|
-
find(:coupon_code => coupon_code)
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.create(opts)
|
14
|
-
response = Twocheckout::API.request(:post, 'products/create_coupon', opts)
|
15
|
-
find(:coupon_code => response['coupon_code'])
|
16
|
-
end
|
17
|
-
|
18
|
-
def update(opts)
|
19
|
-
opts = opts.merge(:coupon_code => self.coupon_code)
|
20
|
-
Twocheckout::API.request(:post, 'products/update_coupon', opts)
|
21
|
-
response = Twocheckout::API.request(:get, 'products/detail_coupon', opts)
|
22
|
-
Coupon.new(response['coupon'])
|
23
|
-
end
|
24
|
-
|
25
|
-
def delete!
|
26
|
-
opts = {:coupon_code => self.coupon_code}
|
27
|
-
Twocheckout::API.request(:post, 'products/delete_coupon', opts)
|
28
|
-
end
|
29
|
-
|
30
|
-
def self.list(opts=nil)
|
31
|
-
Twocheckout::API.request(:get, 'products/list_coupons', opts)
|
32
|
-
end
|
33
|
-
|
34
|
-
protected
|
35
|
-
|
36
|
-
def _key
|
37
|
-
self.coupon_code
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
41
|
-
end
|
data/lib/twocheckout/option.rb
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
module Twocheckout
|
2
|
-
class Option < HashObject
|
3
|
-
|
4
|
-
#
|
5
|
-
# Finds option by ID and returns a Option object
|
6
|
-
#
|
7
|
-
def self.find(options)
|
8
|
-
response = Twocheckout::API.request(:get, 'products/detail_option', options)
|
9
|
-
Option.new(response['option'][0])
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.with_option_id(option_id)
|
13
|
-
find(:option_id => option_id)
|
14
|
-
end
|
15
|
-
|
16
|
-
#
|
17
|
-
# Creates a new product option
|
18
|
-
#
|
19
|
-
def self.create(opts)
|
20
|
-
response = Twocheckout::API.request(:post, 'products/create_option', opts)
|
21
|
-
find(:option_id => response['option_id'])
|
22
|
-
end
|
23
|
-
|
24
|
-
#
|
25
|
-
# Updates option and returns a new object
|
26
|
-
#
|
27
|
-
def update(opts)
|
28
|
-
opts = opts.merge(:option_id => self.option_id)
|
29
|
-
Twocheckout::API.request(:post, 'products/update_option', opts)
|
30
|
-
response = Twocheckout::API.request(:get, 'products/detail_option', opts)
|
31
|
-
Option.new(response['option'][0])
|
32
|
-
end
|
33
|
-
|
34
|
-
#
|
35
|
-
# Deletes the option and returns the response
|
36
|
-
#
|
37
|
-
def delete!
|
38
|
-
opts = {:option_id => self.option_id}
|
39
|
-
Twocheckout::API.request(:post, 'products/delete_option', opts)
|
40
|
-
end
|
41
|
-
|
42
|
-
#
|
43
|
-
# An array to index options list
|
44
|
-
#
|
45
|
-
def self.list(opts=nil)
|
46
|
-
response = Twocheckout::API.request(:get, 'products/list_options', opts)
|
47
|
-
response['options']
|
48
|
-
end
|
49
|
-
|
50
|
-
protected
|
51
|
-
|
52
|
-
def _key
|
53
|
-
self.option_id
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|
57
|
-
end
|
data/twocheckout-0.1.3.gem
DELETED
Binary file
|