twocheckout 0.0.1 → 0.1.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.
- metadata +13 -28
- data/.gitignore +0 -5
- data/LICENSE +0 -21
- data/README.md +0 -102
- data/lib/test/test_twocheckout.rb +0 -260
- data/lib/twocheckout.rb +0 -62
- data/lib/twocheckout/api/company.rb +0 -8
- data/lib/twocheckout/api/contact.rb +0 -8
- data/lib/twocheckout/api/coupon.rb +0 -24
- data/lib/twocheckout/api/option.rb +0 -24
- data/lib/twocheckout/api/product.rb +0 -24
- data/lib/twocheckout/api/sale.rb +0 -84
- data/lib/twocheckout/charge.rb +0 -26
- data/lib/twocheckout/ins.rb +0 -28
- data/lib/twocheckout/message.rb +0 -18
- data/lib/twocheckout/return.rb +0 -34
- data/lib/twocheckout/util.rb +0 -37
- data/twocheckout.gemspec +0 -21
metadata
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twocheckout
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Craig Christenson
|
9
|
+
- Ernesto Garcia
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date: 2012-
|
13
|
+
date: 2012-10-24 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: rest-client
|
@@ -18,7 +19,7 @@ dependencies:
|
|
18
19
|
requirements:
|
19
20
|
- - ~>
|
20
21
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
22
|
+
version: 1.6.7
|
22
23
|
type: :runtime
|
23
24
|
prerelease: false
|
24
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,31 +27,16 @@ dependencies:
|
|
26
27
|
requirements:
|
27
28
|
- - ~>
|
28
29
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
30
|
-
description: 0.0
|
31
|
-
email:
|
30
|
+
version: 1.6.7
|
31
|
+
description: 0.1.0
|
32
|
+
email:
|
33
|
+
- christensoncraig@gmail.com
|
34
|
+
- ernesto+git@gnapse.com
|
32
35
|
executables: []
|
33
36
|
extensions: []
|
34
37
|
extra_rdoc_files: []
|
35
|
-
files:
|
36
|
-
|
37
|
-
- LICENSE
|
38
|
-
- README.md
|
39
|
-
- lib/test/test_twocheckout.rb
|
40
|
-
- lib/twocheckout.rb
|
41
|
-
- lib/twocheckout/api/company.rb
|
42
|
-
- lib/twocheckout/api/contact.rb
|
43
|
-
- lib/twocheckout/api/coupon.rb
|
44
|
-
- lib/twocheckout/api/option.rb
|
45
|
-
- lib/twocheckout/api/product.rb
|
46
|
-
- lib/twocheckout/api/sale.rb
|
47
|
-
- lib/twocheckout/charge.rb
|
48
|
-
- lib/twocheckout/ins.rb
|
49
|
-
- lib/twocheckout/message.rb
|
50
|
-
- lib/twocheckout/return.rb
|
51
|
-
- lib/twocheckout/util.rb
|
52
|
-
- twocheckout.gemspec
|
53
|
-
homepage: https://github.com/craigchristenson
|
38
|
+
files: []
|
39
|
+
homepage: http://github.com/craigchristenson
|
54
40
|
licenses: []
|
55
41
|
post_install_message:
|
56
42
|
rdoc_options: []
|
@@ -68,11 +54,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
54
|
- - ! '>='
|
69
55
|
- !ruby/object:Gem::Version
|
70
56
|
version: '0'
|
71
|
-
requirements:
|
72
|
-
- none
|
57
|
+
requirements: []
|
73
58
|
rubyforge_project:
|
74
59
|
rubygems_version: 1.8.24
|
75
60
|
signing_key:
|
76
61
|
specification_version: 3
|
77
|
-
summary: 2Checkout
|
62
|
+
summary: Ruby wrapper for 2Checkout API
|
78
63
|
test_files: []
|
data/LICENSE
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
The MIT License
|
2
|
-
|
3
|
-
Copyright (c) 2012 - Craig Christenson
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
13
|
-
copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
-
SOFTWARE.
|
data/README.md
DELETED
@@ -1,102 +0,0 @@
|
|
1
|
-
2Checkout Ruby Library
|
2
|
-
=====================
|
3
|
-
|
4
|
-
This library provides developers with a simple set of bindings to the 2Checkout purchase routine, Instant Notification Service and Back Office API.
|
5
|
-
|
6
|
-
To use, download or clone the repository.
|
7
|
-
|
8
|
-
```shell
|
9
|
-
git clone https://github.com/craigchristenson/2checkout-ruby.git
|
10
|
-
```
|
11
|
-
|
12
|
-
Or import into your Gemfile
|
13
|
-
|
14
|
-
```ruby
|
15
|
-
gem 'twocheckout', :git => "git://github.com/craigchristenson/2checkout-ruby.git"
|
16
|
-
```
|
17
|
-
|
18
|
-
Full documentation for each binding will be provided in the [Wiki](https://github.com/craigchristenson/2checkout-ruby/wiki).
|
19
|
-
|
20
|
-
|
21
|
-
Example API Usage
|
22
|
-
-----------------
|
23
|
-
|
24
|
-
*Example Usage:*
|
25
|
-
|
26
|
-
```ruby
|
27
|
-
Twocheckout.api_credentials=({'username' => 'APIuser1817037', 'password' => 'APIpass1817037'})
|
28
|
-
|
29
|
-
@action = Twocheckout::Sale.refund({'sale_id' => 4769044324, 'comment' => "test refund", 'category' => 1})
|
30
|
-
puts @action
|
31
|
-
```
|
32
|
-
|
33
|
-
*Example Response:*
|
34
|
-
|
35
|
-
```json
|
36
|
-
{
|
37
|
-
"response_code" : "OK",
|
38
|
-
"response_message" : "refund added to invoice"
|
39
|
-
}
|
40
|
-
```
|
41
|
-
|
42
|
-
Example Checkout Usage:
|
43
|
-
-----------------------
|
44
|
-
|
45
|
-
*Example Usage:*
|
46
|
-
|
47
|
-
```ruby
|
48
|
-
require "sinatra"
|
49
|
-
|
50
|
-
get '/' do
|
51
|
-
@@form = Twocheckout::Charge.submit({'sid' => 1817037, 'cart_order_id' => 'Example Sale', 'total' => 1.00})
|
52
|
-
@@form
|
53
|
-
end
|
54
|
-
```
|
55
|
-
|
56
|
-
Example Return Usage:
|
57
|
-
---------------------
|
58
|
-
|
59
|
-
*Example Usage:*
|
60
|
-
|
61
|
-
```ruby
|
62
|
-
require "sinatra"
|
63
|
-
|
64
|
-
post '/' do
|
65
|
-
@@response = Twocheckout::Return.request({ :credentials => {'sid' => '532001', 'secret' => 'tango'}, :params => params})
|
66
|
-
@@response.inspect
|
67
|
-
end
|
68
|
-
```
|
69
|
-
|
70
|
-
*Example Response:*
|
71
|
-
|
72
|
-
```json
|
73
|
-
{
|
74
|
-
"code" : "PASS",
|
75
|
-
"message" : "Hash Matched"
|
76
|
-
}
|
77
|
-
```
|
78
|
-
|
79
|
-
Example INS Usage:
|
80
|
-
------------------
|
81
|
-
|
82
|
-
*Example Usage:*
|
83
|
-
|
84
|
-
```ruby
|
85
|
-
require "sinatra"
|
86
|
-
|
87
|
-
post '/' do
|
88
|
-
@@response = Twocheckout::Ins.request({ :credentials => {'sid' => 532001, 'secret' => 'tango'}, :params => params})
|
89
|
-
@@response.inspect
|
90
|
-
end
|
91
|
-
```
|
92
|
-
|
93
|
-
*Example Response:*
|
94
|
-
|
95
|
-
```json
|
96
|
-
{
|
97
|
-
"code" : "PASS",
|
98
|
-
"message" : "Hash Matched"
|
99
|
-
}
|
100
|
-
```
|
101
|
-
|
102
|
-
Full documentation for each binding will be provided in the [Wiki](https://github.com/craigchristenson/2checkout-ruby/wiki).
|
@@ -1,260 +0,0 @@
|
|
1
|
-
require 'minitest/spec'
|
2
|
-
require 'minitest/autorun'
|
3
|
-
require '../../lib/twocheckout.rb'
|
4
|
-
|
5
|
-
describe Twocheckout::Sale do
|
6
|
-
before do
|
7
|
-
Twocheckout.api_credentials=({'username' => 'APIuser1817037', 'password' => 'APIpass1817037'})
|
8
|
-
end
|
9
|
-
|
10
|
-
#retrieve sale
|
11
|
-
it "Sale retrieve returns sale" do
|
12
|
-
action = Twocheckout::Sale.retrieve({'sale_id' => 4786293822})
|
13
|
-
action = JSON.parse(action)
|
14
|
-
assert_equal('Sale detail retrieved', action['response_message'])
|
15
|
-
end
|
16
|
-
|
17
|
-
#retrieve invoice
|
18
|
-
it "Sale retrieve returns sale" do
|
19
|
-
action = Twocheckout::Sale.retrieve({'invoice_id' => 4786293831})
|
20
|
-
action = JSON.parse(action)
|
21
|
-
assert_equal('Sale detail retrieved', action['response_message'])
|
22
|
-
end
|
23
|
-
|
24
|
-
#retrieve list
|
25
|
-
it "Sale retrieve returns list" do
|
26
|
-
action = Twocheckout::Sale.retrieve()
|
27
|
-
action = JSON.parse(action)
|
28
|
-
assert_equal('Sales summaries retrieved successfully.', action['response_message'])
|
29
|
-
end
|
30
|
-
|
31
|
-
#refund sale
|
32
|
-
it "Sale refund returns successful result when passing sale_id" do
|
33
|
-
action = Twocheckout::Sale.refund({'sale_id' => 4786293822, 'comment' => "test refund", 'category' => 1})
|
34
|
-
action = JSON.parse(action)
|
35
|
-
if action['response_message']
|
36
|
-
assert_equal('refund added to invoice', action['response_message'])
|
37
|
-
else
|
38
|
-
assert_equal('Invoice was already refunded.', action["errors"][0]["message"])
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
#refund invoice
|
43
|
-
it "Sale refund returns successful result when passing invoice_id" do
|
44
|
-
action = Twocheckout::Sale.refund({'invoice_id' => 4786293831, 'comment' => "test refund", 'category' => 1})
|
45
|
-
action = JSON.parse(action)
|
46
|
-
if action['response_message']
|
47
|
-
assert_equal('refund added to invoice', action['response_message'])
|
48
|
-
else
|
49
|
-
assert_equal("Invoice was already refunded.", action["errors"][0]["message"])
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
#refund lineitem
|
54
|
-
it "Sale refund returns successful result when passing lineitem_id" do
|
55
|
-
action = Twocheckout::Sale.refund({'lineitem_id' => 4789788509, 'comment' => "test refund", 'category' => 1})
|
56
|
-
action = JSON.parse(action)
|
57
|
-
if action['response_message']
|
58
|
-
assert_equal('lineitem refunded', action['response_message'])
|
59
|
-
else
|
60
|
-
assert_equal('This lineitem cannot be refunded.', action["errors"][0]["message"])
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
#stop recurring lineitem
|
65
|
-
it "Sale stop returns successful result when passing lineitem_id" do
|
66
|
-
action = Twocheckout::Sale.stop({'lineitem_id' => 4789788509})
|
67
|
-
action = JSON.parse(action)
|
68
|
-
if action['response_message']
|
69
|
-
assert_equal('Recurring billing stopped for lineitem', action['response_message'])
|
70
|
-
else
|
71
|
-
assert_equal('Lineitem is not scheduled to recur.', action["errors"][0]["message"])
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
#stop recurring sale
|
76
|
-
it "Sale stop returns successful result when passing sale_id" do
|
77
|
-
action = Twocheckout::Sale.stop('sale_id' => 4786293822)
|
78
|
-
action = JSON.parse(action)
|
79
|
-
if action[0]
|
80
|
-
assert_equal('Recurring billing stopped for lineitem', action['response_message'])
|
81
|
-
else
|
82
|
-
assert_equal("No Active recurring lineitems.", action["errors"][0]["message"])
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
#create comment
|
87
|
-
it "Sale comment returns successful result" do
|
88
|
-
action = Twocheckout::Sale.comment({'sale_id' => 4786293822, 'sale_comment' => "test"})
|
89
|
-
action = JSON.parse(action)
|
90
|
-
assert_equal('Created comment successfully.', action['response_message'])
|
91
|
-
end
|
92
|
-
|
93
|
-
#mark shipped
|
94
|
-
it "Sale ship returns successful result" do
|
95
|
-
action = Twocheckout::Sale.ship({'sale_id' => 4786293822, 'tracking_number' => "test"})
|
96
|
-
action = JSON.parse(action)
|
97
|
-
if action['response_message']
|
98
|
-
assert_equal('Sale marked shipped.', action['response_message'])
|
99
|
-
else
|
100
|
-
assert_equal('Item not shippable.', action["errors"][0]["message"])
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
#reauth
|
105
|
-
it "Sale reauth returns successful result" do
|
106
|
-
action = Twocheckout::Sale.reauth({'sale_id' => 4786293822})
|
107
|
-
action = JSON.parse(action)
|
108
|
-
if action['response_message']
|
109
|
-
assert_equal('Payment reauthorized.', action['response_message'])
|
110
|
-
else
|
111
|
-
assert_equal('Payment is already pending or deposited and cannot be reauthorized.', action["errors"][0]["message"])
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
describe Twocheckout::Product do
|
117
|
-
before do
|
118
|
-
Twocheckout.api_credentials=({'username' => 'APIuser1817037', 'password' => 'APIpass1817037'})
|
119
|
-
action = Twocheckout::Product.create({'name' => "test product", 'price' => 1.00})
|
120
|
-
action = JSON.parse(action)
|
121
|
-
@product_id = action['product_id']
|
122
|
-
end
|
123
|
-
|
124
|
-
#create
|
125
|
-
it "Product create returns successful result" do
|
126
|
-
action = Twocheckout::Product.create({'name' => "test product", 'price' => 1.00})
|
127
|
-
action = JSON.parse(action)
|
128
|
-
assert_equal('Product successfully created', action['response_message'])
|
129
|
-
end
|
130
|
-
|
131
|
-
#retrieve list
|
132
|
-
it "Product retrieve returns successful result" do
|
133
|
-
action = Twocheckout::Product.retrieve()
|
134
|
-
action = JSON.parse(action)
|
135
|
-
assert_equal('Product list successfully retrieved.', action['response_message'])
|
136
|
-
end
|
137
|
-
|
138
|
-
#retrieve product
|
139
|
-
it "Product retrieve returns successful result" do
|
140
|
-
action = Twocheckout::Product.retrieve({'product_id' => @product_id})
|
141
|
-
action = JSON.parse(action)
|
142
|
-
assert_equal('Product detail information retrieved successfully', action['response_message'])
|
143
|
-
end
|
144
|
-
|
145
|
-
#update
|
146
|
-
it "Product update returns successful result" do
|
147
|
-
action = Twocheckout::Product.update({'product_id' => @product_id, 'name' => "test product"})
|
148
|
-
action = JSON.parse(action)
|
149
|
-
assert_equal('Product successfully updated', action['response_message'])
|
150
|
-
end
|
151
|
-
|
152
|
-
#delete
|
153
|
-
it "Product delete returns successful result" do
|
154
|
-
action = Twocheckout::Product.delete({'product_id' => @product_id})
|
155
|
-
action = JSON.parse(action)
|
156
|
-
assert_equal('Product successfully deleted.', action['response_message'])
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
describe Twocheckout::Coupon do
|
161
|
-
before do
|
162
|
-
Twocheckout.api_credentials=({'username' => 'APIuser1817037', 'password' => 'APIpass1817037'})
|
163
|
-
action = Twocheckout::Coupon.create({'date_expire' => "2099-12-01",
|
164
|
-
'type' => "shipping", 'minimum_purchase' => 1.00})
|
165
|
-
action = JSON.parse(action)
|
166
|
-
@coupon_code = action['coupon_code']
|
167
|
-
end
|
168
|
-
|
169
|
-
#create
|
170
|
-
it "Coupon create returns successful result" do
|
171
|
-
action = Twocheckout::Coupon.create({'date_expire' => "2099-12-01",
|
172
|
-
'type' => "shipping", 'minimum_purchase' => 1.00})
|
173
|
-
action = JSON.parse(action)
|
174
|
-
assert_equal('Coupon successfully created', action['response_message'])
|
175
|
-
end
|
176
|
-
|
177
|
-
#retrieve
|
178
|
-
it "Coupon retrieve returns successful result" do
|
179
|
-
action = Twocheckout::Coupon.retrieve()
|
180
|
-
action = JSON.parse(action)
|
181
|
-
assert_equal('Coupon information retrieved successfully.', action['response_message'])
|
182
|
-
end
|
183
|
-
|
184
|
-
#update
|
185
|
-
it "Coupon update returns successful result" do
|
186
|
-
action = Twocheckout::Coupon.update({'coupon_code' => @coupon_code, 'date_expire' => "2099-12-10"})
|
187
|
-
action = JSON.parse(action)
|
188
|
-
assert_equal('Coupon updated successfully', action['response_message'])
|
189
|
-
end
|
190
|
-
|
191
|
-
#delete
|
192
|
-
it "Coupon delete returns successful result" do
|
193
|
-
action = Twocheckout::Coupon.delete({'coupon_code' => @coupon_code})
|
194
|
-
action = JSON.parse(action)
|
195
|
-
assert_equal('Coupon successfully deleted.', action['response_message'])
|
196
|
-
end
|
197
|
-
end
|
198
|
-
|
199
|
-
describe Twocheckout::Option do
|
200
|
-
before do
|
201
|
-
Twocheckout.api_credentials=({'username' => 'APIuser1817037', 'password' => 'APIpass1817037'})
|
202
|
-
action = Twocheckout::Option.create({'option_name' => "test product", 'option_value_name' => "example",'option_value_surcharge' => 1.00})
|
203
|
-
action = JSON.parse(action)
|
204
|
-
@option_id = action['option_id']
|
205
|
-
end
|
206
|
-
|
207
|
-
#create
|
208
|
-
it "Option create returns successful result" do
|
209
|
-
action = Twocheckout::Option.create({'option_name' => "test product", 'option_value_name' => "example",'option_value_surcharge' => 1.00})
|
210
|
-
action = JSON.parse(action)
|
211
|
-
assert_equal('Option created successfully', action['response_message'])
|
212
|
-
end
|
213
|
-
|
214
|
-
#retrieve
|
215
|
-
it "Option retrieve returns successful result" do
|
216
|
-
action = Twocheckout::Option.retrieve()
|
217
|
-
action = JSON.parse(action)
|
218
|
-
assert_equal('Option information retrieved successfully.', action['response_message'])
|
219
|
-
end
|
220
|
-
|
221
|
-
#update
|
222
|
-
it "Option update returns successful result" do
|
223
|
-
action = Twocheckout::Option.update({'option_name' => "test option", 'option_id' => @option_id})
|
224
|
-
action = JSON.parse(action)
|
225
|
-
assert_equal('Option updated successfully', action['response_message'])
|
226
|
-
end
|
227
|
-
|
228
|
-
#delete
|
229
|
-
it "Option delete returns successful result" do
|
230
|
-
action = Twocheckout::Option.delete({'option_id' => @option_id})
|
231
|
-
action = JSON.parse(action)
|
232
|
-
assert_equal('Option deleted successfully', action['response_message'])
|
233
|
-
end
|
234
|
-
end
|
235
|
-
|
236
|
-
describe Twocheckout::Return do
|
237
|
-
before do
|
238
|
-
@params = {'order_number' => '4789848870', 'total' => '0.01', 'key' => 'CDF3E502AA1597DD4401760783432337'}
|
239
|
-
end
|
240
|
-
|
241
|
-
#check
|
242
|
-
it "Return check returns successful result" do
|
243
|
-
action = Twocheckout::Return.request({ :credentials => {'sid' => '1817037', 'secret' => 'tango'}, :params => @params})
|
244
|
-
action = JSON.parse(action)
|
245
|
-
assert_equal('PASS', action['code'])
|
246
|
-
end
|
247
|
-
end
|
248
|
-
|
249
|
-
describe Twocheckout::Ins do
|
250
|
-
before do
|
251
|
-
@params = {'sale_id' => '4789848870', 'invoice_id' => '4789848879', 'md5_hash' => '827220324C722873694758F38D8D3624'}
|
252
|
-
end
|
253
|
-
|
254
|
-
#check
|
255
|
-
it "Return check returns successful result" do
|
256
|
-
action = Twocheckout::Ins.request({ :credentials => {'sid' => '1817037', 'secret' => 'tango'}, :params => @params})
|
257
|
-
action = JSON.parse(action)
|
258
|
-
assert_equal('PASS', action['code'])
|
259
|
-
end
|
260
|
-
end
|
data/lib/twocheckout.rb
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
require 'rest_client'
|
2
|
-
require 'rubygems'
|
3
|
-
require 'cgi'
|
4
|
-
require 'json'
|
5
|
-
require 'net/http'
|
6
|
-
require 'base64'
|
7
|
-
require 'digest/md5'
|
8
|
-
|
9
|
-
require File.dirname(__FILE__) + '/twocheckout/api/sale.rb'
|
10
|
-
require File.dirname(__FILE__) + '/twocheckout/api/company.rb'
|
11
|
-
require File.dirname(__FILE__) + '/twocheckout/api/contact.rb'
|
12
|
-
require File.dirname(__FILE__) + '/twocheckout/api/product.rb'
|
13
|
-
require File.dirname(__FILE__) + '/twocheckout/api/option.rb'
|
14
|
-
require File.dirname(__FILE__) + '/twocheckout/api/coupon.rb'
|
15
|
-
require File.dirname(__FILE__) + '/twocheckout/charge.rb'
|
16
|
-
require File.dirname(__FILE__) + '/twocheckout/return.rb'
|
17
|
-
require File.dirname(__FILE__) + '/twocheckout/ins.rb'
|
18
|
-
require File.dirname(__FILE__) + '/twocheckout/util.rb'
|
19
|
-
require File.dirname(__FILE__) + '/twocheckout/message.rb'
|
20
|
-
|
21
|
-
module Twocheckout
|
22
|
-
@api_base = 'https://www.2checkout.com/api/'
|
23
|
-
@api_credentials = nil
|
24
|
-
|
25
|
-
def self.api_url(url='')
|
26
|
-
@api_base + url
|
27
|
-
end
|
28
|
-
|
29
|
-
def self.api_credentials=(options = {})
|
30
|
-
@api_credentials = options
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.api_base=(api_base)
|
34
|
-
@api_base = api_base
|
35
|
-
end
|
36
|
-
|
37
|
-
def self.request(method, url, params=nil)
|
38
|
-
|
39
|
-
if method == :get
|
40
|
-
@url = api_url(url) + '?' + params.map{|k,v| "#{k}=#{v}"}.join('&')
|
41
|
-
params = nil
|
42
|
-
elsif method == :post
|
43
|
-
@url = api_url(url)
|
44
|
-
else
|
45
|
-
|
46
|
-
end
|
47
|
-
|
48
|
-
opts = {
|
49
|
-
:method => method,
|
50
|
-
:url => @url,
|
51
|
-
:headers => {:accept => :json, :content_type => :json},
|
52
|
-
:user => @api_credentials['username'],
|
53
|
-
:password => @api_credentials['password'],
|
54
|
-
:payload => params
|
55
|
-
}
|
56
|
-
begin
|
57
|
-
RestClient::Request.execute(opts)
|
58
|
-
rescue => e
|
59
|
-
TwocheckoutMessage.new(e.response).retrieve
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
module Twocheckout
|
2
|
-
class Coupon
|
3
|
-
|
4
|
-
def self.create(params={})
|
5
|
-
Twocheckout.request(:post, 'products/create_coupon', params)
|
6
|
-
end
|
7
|
-
|
8
|
-
def self.retrieve(params={})
|
9
|
-
if params.has_key?("coupon_code")
|
10
|
-
Twocheckout.request(:get, 'products/detail_coupon', params)
|
11
|
-
else
|
12
|
-
Twocheckout.request(:get, 'products/list_coupons', params)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.update(params={})
|
17
|
-
Twocheckout.request(:post, 'products/update_coupon', params)
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.delete(params={})
|
21
|
-
Twocheckout.request(:post, 'products/delete_coupon', params)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
module Twocheckout
|
2
|
-
class Option
|
3
|
-
|
4
|
-
def self.create(params={})
|
5
|
-
Twocheckout.request(:post, 'products/create_option', params)
|
6
|
-
end
|
7
|
-
|
8
|
-
def self.retrieve(params={})
|
9
|
-
if params.has_key?("option_id")
|
10
|
-
Twocheckout.request(:get, 'products/detail_option', params)
|
11
|
-
else
|
12
|
-
Twocheckout.request(:get, 'products/list_options', params)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.update(params={})
|
17
|
-
Twocheckout.request(:post, 'products/update_option', params)
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.delete(params={})
|
21
|
-
Twocheckout.request(:post, 'products/delete_option', params)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
module Twocheckout
|
2
|
-
class Product
|
3
|
-
|
4
|
-
def self.create(params={})
|
5
|
-
Twocheckout.request(:post, 'products/create_product', params)
|
6
|
-
end
|
7
|
-
|
8
|
-
def self.retrieve(params={})
|
9
|
-
if params.has_key?("product_id")
|
10
|
-
Twocheckout.request(:get, 'products/detail_product', params)
|
11
|
-
else
|
12
|
-
Twocheckout.request(:get, 'products/list_products', params)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.update(params={})
|
17
|
-
Twocheckout.request(:post, 'products/update_product', params)
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.delete(params={})
|
21
|
-
Twocheckout.request(:post, 'products/delete_product', params)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
data/lib/twocheckout/api/sale.rb
DELETED
@@ -1,84 +0,0 @@
|
|
1
|
-
module Twocheckout
|
2
|
-
class Sale
|
3
|
-
|
4
|
-
def self.retrieve(params={})
|
5
|
-
if params.has_key?("sale_id") || params.has_key?("invoice_id")
|
6
|
-
Twocheckout.request(:get, 'sales/detail_sale', params)
|
7
|
-
else
|
8
|
-
Twocheckout.request(:get, 'sales/list_sales', params)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.refund(params={})
|
13
|
-
if params.has_key?("lineitem_id")
|
14
|
-
result = Twocheckout.request(:post, 'sales/refund_lineitem', params)
|
15
|
-
elsif params.has_key?("sale_id") || params.has_key?("invoice_id")
|
16
|
-
result = Twocheckout.request(:post, 'sales/refund_invoice', params)
|
17
|
-
else
|
18
|
-
message = {:errors => [{:code => "INVALID PARAMETER", :message => "You must pass a sale_id, invoice_id or lineitem_id."}]}
|
19
|
-
result = TwocheckoutMessage.new(message).retrieve
|
20
|
-
end
|
21
|
-
result
|
22
|
-
end
|
23
|
-
|
24
|
-
def self.stop(params={})
|
25
|
-
if params.has_key?("lineitem_id")
|
26
|
-
result = Twocheckout.request(:post, 'sales/stop_lineitem_recurring', params)
|
27
|
-
elsif params.has_key?("sale_id")
|
28
|
-
@sale = Twocheckout.request(:get, 'sales/detail_sale', params)
|
29
|
-
@sale = JSON.parse(@sale)
|
30
|
-
if @sale.has_key?("errors")
|
31
|
-
return @sale
|
32
|
-
end
|
33
|
-
@lineitems = Twocheckout::Util.active(@sale)
|
34
|
-
if @lineitems.empty?
|
35
|
-
message = {:errors => [{:code => "NOTICE", :message => "No Active recurring lineitems."}]}
|
36
|
-
result = TwocheckoutMessage.new(message).retrieve
|
37
|
-
else
|
38
|
-
result = {}
|
39
|
-
i=0
|
40
|
-
@lineitems.each do |k,v|
|
41
|
-
params={'lineitem_id' => v}
|
42
|
-
response = Twocheckout.request(:post, 'sales/stop_lineitem_recurring', params)
|
43
|
-
result[i] = response
|
44
|
-
i+=1
|
45
|
-
end
|
46
|
-
end
|
47
|
-
else
|
48
|
-
message = {:errors => [{:code => "INVALID PARAMETER", :message => "You must pass a sale_id or lineitem_id."}]}
|
49
|
-
result = TwocheckoutMessage.new(message).retrieve
|
50
|
-
end
|
51
|
-
result
|
52
|
-
end
|
53
|
-
|
54
|
-
def self.comment(params={})
|
55
|
-
if params.has_key?("sale_id" && "sale_comment")
|
56
|
-
result = Twocheckout.request(:post, 'sales/create_comment', params)
|
57
|
-
else
|
58
|
-
message = {:errors => [{:code => "INVALID PARAMETER", :message => "You must pass a sale_id and sale_comment."}]}
|
59
|
-
result = TwocheckoutMessage.new(message).retrieve
|
60
|
-
end
|
61
|
-
result
|
62
|
-
end
|
63
|
-
|
64
|
-
def self.ship(params={})
|
65
|
-
if params.has_key?("sale_id" && "tracking_number")
|
66
|
-
result = Twocheckout.request(:post, 'sales/mark_shipped', params)
|
67
|
-
else
|
68
|
-
message = {:errors => [{:code => "INVALID PARAMETER", :message => "You must pass a sale_id and tracking_number."}]}
|
69
|
-
result = TwocheckoutMessage.new(message).retrieve
|
70
|
-
end
|
71
|
-
result
|
72
|
-
end
|
73
|
-
|
74
|
-
def self.reauth(params={})
|
75
|
-
if params.has_key?("sale_id") || params.has_key?("invoice_id")
|
76
|
-
result = Twocheckout.request(:post, 'sales/reauth', params)
|
77
|
-
else
|
78
|
-
message = {:errors => [{:code => "INVALID PARAMETER", :message => "You must pass a sale_id or invoice_id."}]}
|
79
|
-
result = TwocheckoutMessage.new(message).retrieve
|
80
|
-
end
|
81
|
-
result
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
data/lib/twocheckout/charge.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
module Twocheckout
|
2
|
-
class Charge
|
3
|
-
|
4
|
-
def self.form(params={})
|
5
|
-
@form = "<form id=\"2checkout\" action=\"https://www.2checkout.com/checkout/spurchase\" method=\"post\">\n";
|
6
|
-
params.each do |k,v|
|
7
|
-
@form = @form + "<input type=\"hidden\" name=\"" + k + "\" value=\"" + v.to_s + "\" />\n"
|
8
|
-
end
|
9
|
-
@form + "<input type=\"submit\" value=\"Proceed to Checkout\" />\n</form>"
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.submit(params={})
|
13
|
-
@form = "<form id=\"2checkout\" action=\"https://www.2checkout.com/checkout/spurchase\" method=\"post\">\n";
|
14
|
-
params.each do |k,v|
|
15
|
-
@form = @form + "<input type=\"hidden\" name=\"" + k + "\" value=\"" + v.to_s + "\" />\n"
|
16
|
-
end
|
17
|
-
@form = @form + "</form>\n"
|
18
|
-
@form = @form + "<script type=\"text/javascript\">document.getElementById('2checkout').submit();</script>"
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.link(params={}, url="https://www.2checkout.com/checkout/spurchase?")
|
22
|
-
@querystring = params.map{|k,v| "#{CGI.escape(k)}=#{CGI.escape(v)}"}.join("&")
|
23
|
-
@purchase_url = url + @querystring
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
data/lib/twocheckout/ins.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
module Twocheckout
|
2
|
-
class Ins
|
3
|
-
|
4
|
-
# Checks against MD5 Hash
|
5
|
-
def self.check(sale_id, sid, invoice_id, secret, key)
|
6
|
-
Digest::MD5.hexdigest("#{sale_id}#{sid}#{invoice_id}#{secret}").upcase == key
|
7
|
-
end
|
8
|
-
|
9
|
-
# Parses Header Redirect Query String
|
10
|
-
def self.request(options={})
|
11
|
-
params = options[:params]
|
12
|
-
credentials = options[:credentials]
|
13
|
-
if params.is_a?(Hash)
|
14
|
-
if check(params['sale_id'], credentials['sid'], params['invoice_id'], credentials['secret'], params['md5_hash'])
|
15
|
-
message = {:code => "PASS", :message => "Hash Matched"}
|
16
|
-
result = TwocheckoutMessage.new(message).retrieve
|
17
|
-
else
|
18
|
-
message = {:code => "FAIL", :message => "Hash Mismatch"}
|
19
|
-
result = TwocheckoutMessage.new(message).retrieve
|
20
|
-
end
|
21
|
-
else
|
22
|
-
message = {:errors => [{:code => "INVALID PARAMETER", :message => "Hash was not passed"}]}
|
23
|
-
result = TwocheckoutMessage.new(message).retrieve
|
24
|
-
end
|
25
|
-
result
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
data/lib/twocheckout/message.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
module Twocheckout
|
2
|
-
class TwocheckoutMessage < StandardError
|
3
|
-
attr_reader :message
|
4
|
-
|
5
|
-
def initialize(message=nil)
|
6
|
-
@message = message
|
7
|
-
end
|
8
|
-
|
9
|
-
def retrieve
|
10
|
-
if @message.is_a?(Hash)
|
11
|
-
@message = JSON.generate(@message)
|
12
|
-
"#{@message}"
|
13
|
-
else
|
14
|
-
"#{@message}"
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
data/lib/twocheckout/return.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
module Twocheckout
|
2
|
-
class Return
|
3
|
-
|
4
|
-
# Checks against MD5 Hash
|
5
|
-
def self.check(secret, sid, order_number, total, key)
|
6
|
-
Digest::MD5.hexdigest("#{secret}#{sid}#{order_number}#{total}").upcase == key
|
7
|
-
end
|
8
|
-
|
9
|
-
# Parses Header Redirect Query String
|
10
|
-
def self.request(options={})
|
11
|
-
params = options[:params]
|
12
|
-
credentials = options[:credentials]
|
13
|
-
if params.is_a?(String)
|
14
|
-
params = Twocheckout::Util.parse(params)
|
15
|
-
end
|
16
|
-
if params['demo'] == 'Y'
|
17
|
-
params['order_number'] = 1
|
18
|
-
end
|
19
|
-
if params.is_a?(Hash)
|
20
|
-
if check(credentials['secret'], credentials['sid'], params['order_number'], params['total'], params['key'])
|
21
|
-
message = {:code => "PASS", :message => "Hash Matched"}
|
22
|
-
result = TwocheckoutMessage.new(message).retrieve
|
23
|
-
else
|
24
|
-
message = {:code => "FAIL", :message => "Hash Mismatch"}
|
25
|
-
result = TwocheckoutMessage.new(message).retrieve
|
26
|
-
end
|
27
|
-
else
|
28
|
-
message = {:errors => [{:code => "INVALID PARAMETER", :message => "Hash was not passed"}]}
|
29
|
-
result = TwocheckoutMessage.new(message).retrieve
|
30
|
-
end
|
31
|
-
result
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
data/lib/twocheckout/util.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
module Twocheckout
|
2
|
-
class Util
|
3
|
-
|
4
|
-
# Parse Header Redirect
|
5
|
-
def self.parse(querystring)
|
6
|
-
params = querystring.split('&').inject({}) do |result, q|
|
7
|
-
k,v = q.split('=')
|
8
|
-
if !v.nil?
|
9
|
-
result.merge({k => v})
|
10
|
-
elsif !result.key?(k)
|
11
|
-
result.merge({k => true})
|
12
|
-
else
|
13
|
-
result
|
14
|
-
end
|
15
|
-
end
|
16
|
-
params
|
17
|
-
end
|
18
|
-
|
19
|
-
# Get active recurring lineitems
|
20
|
-
def self.active(params)
|
21
|
-
@invoice = params['sale']['invoices'].last['lineitems']
|
22
|
-
@lineitems = {}
|
23
|
-
i=0
|
24
|
-
@invoice.each do |li|
|
25
|
-
if li['billing']['recurring_status'] == 'active'
|
26
|
-
li.each do |k,v|
|
27
|
-
if k == "lineitem_id"
|
28
|
-
@lineitems[i] = v
|
29
|
-
i+=1
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
@lineitems
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
data/twocheckout.gemspec
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
$:.unshift(File.join(File.dirname(__FILE__), 'lib'))
|
3
|
-
|
4
|
-
Gem::Specification.new do |s|
|
5
|
-
s.platform = Gem::Platform::RUBY
|
6
|
-
s.name = 'twocheckout'
|
7
|
-
s.version = '0.0.1'
|
8
|
-
s.summary = '2Checkout Ruby Library'
|
9
|
-
s.description = '0.0.1'
|
10
|
-
s.summary = '2Checkout Ruby Library'
|
11
|
-
s.author = 'Craig Christenson'
|
12
|
-
s.email = 'christensoncraig@gmail.com'
|
13
|
-
s.homepage = 'https://github.com/craigchristenson'
|
14
|
-
s.files = `git ls-files`.split("\n")
|
15
|
-
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
-
s.add_dependency('rest-client', '~> 1.4')
|
18
|
-
s.require_paths = %w{lib}
|
19
|
-
s.requirements << 'none'
|
20
|
-
|
21
|
-
end
|