pay_u 0.4.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 +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +41 -0
- data/LICENSE.txt +21 -0
- data/README.md +141 -0
- data/Rakefile +6 -0
- data/bin/console +23 -0
- data/bin/setup +8 -0
- data/lib/pay_u/base_request.rb +63 -0
- data/lib/pay_u/client.rb +65 -0
- data/lib/pay_u/http_client.rb +42 -0
- data/lib/pay_u/o_auth/authorization.rb +39 -0
- data/lib/pay_u/o_auth/response.rb +18 -0
- data/lib/pay_u/orders/response.rb +61 -0
- data/lib/pay_u/orders/service.rb +32 -0
- data/lib/pay_u/version.rb +3 -0
- data/lib/payu.rb +38 -0
- data/payu.gemspec +43 -0
- metadata +123 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b5da37021ad0126ffb8adb641a058d99afbb7db8ee5910ee1941149ec8c0f609
|
4
|
+
data.tar.gz: e1b7a2fab724cff1825ec14293f0f7c39b6797ae35f4400911de3a860181e2ac
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6a02f9bf74a152b829cea24cb3427073f54496912f5c38ffa3b06117a4d9580d0c82cfdf2ef56f0b0fed8a4dbb9e1a433ce9745d5b3e0c15a125bbcd816d9c94
|
7
|
+
data.tar.gz: 92a636bcf0b22857520cc78ba89a85130b1a68624ad5e36282f00e898be21c00c43b66b261cffe83c82fdcf2109488cbe5f1321cbcabd1b1e0e40750f2ae2686
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
pay_u (0.3.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
coderay (1.1.2)
|
10
|
+
diff-lcs (1.3)
|
11
|
+
method_source (0.9.2)
|
12
|
+
pry (0.12.2)
|
13
|
+
coderay (~> 1.1.0)
|
14
|
+
method_source (~> 0.9.0)
|
15
|
+
rake (10.5.0)
|
16
|
+
rspec (3.9.0)
|
17
|
+
rspec-core (~> 3.9.0)
|
18
|
+
rspec-expectations (~> 3.9.0)
|
19
|
+
rspec-mocks (~> 3.9.0)
|
20
|
+
rspec-core (3.9.0)
|
21
|
+
rspec-support (~> 3.9.0)
|
22
|
+
rspec-expectations (3.9.0)
|
23
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
24
|
+
rspec-support (~> 3.9.0)
|
25
|
+
rspec-mocks (3.9.0)
|
26
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
27
|
+
rspec-support (~> 3.9.0)
|
28
|
+
rspec-support (3.9.0)
|
29
|
+
|
30
|
+
PLATFORMS
|
31
|
+
ruby
|
32
|
+
|
33
|
+
DEPENDENCIES
|
34
|
+
bundler (~> 1.17)
|
35
|
+
pay_u!
|
36
|
+
pry
|
37
|
+
rake (~> 10.0)
|
38
|
+
rspec (~> 3.0)
|
39
|
+
|
40
|
+
BUNDLED WITH
|
41
|
+
1.17.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 michal.kosyk
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
# PayU
|
2
|
+
|
3
|
+
A lightweight client for PayU's payment system.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'payu'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install payu
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
First - read the API documentation here: `http://developers.payu.com/en/restapi.html#overview` to get a grip of what this client does.
|
24
|
+
Configure the library with your PayU Merchant configuration. You can do it like this in `config/initializers/pay_u`:
|
25
|
+
|
26
|
+
```
|
27
|
+
PayU.configure do |c|
|
28
|
+
c.pos_id = ENV['PAY_U_POS_ID']
|
29
|
+
c.second_key = ENV['PAY_U_SECOND_KEY']
|
30
|
+
c.oauth_client_id = ENV['PAY_U_OAUTH_CLIENT_ID']
|
31
|
+
c.oauth_client_secret = ENV['PAY_U_OAUTH_CLIENT_SECRET']
|
32
|
+
c.env = 'sandbox' # optional, it defaults to 'production'
|
33
|
+
c.notify_url = 'https://example.com'
|
34
|
+
end
|
35
|
+
```
|
36
|
+
|
37
|
+
After that, you are free to use it. The main concern here is the PayU::Client which is accessible throught `PayU.client` method.
|
38
|
+
|
39
|
+
Available functionality:
|
40
|
+
|
41
|
+
### Placing orders
|
42
|
+
|
43
|
+
```
|
44
|
+
meta = {
|
45
|
+
"customer_ip": "127.0.0.1",
|
46
|
+
"description": "RTV market",
|
47
|
+
"currency_code": "PLN",
|
48
|
+
"total_amount": "15000",
|
49
|
+
"ext_order_id":"XEGB34325" # your order's id
|
50
|
+
}
|
51
|
+
|
52
|
+
buyer = {
|
53
|
+
email: "john.doe@example.com",
|
54
|
+
phone: "654111654",
|
55
|
+
first_name: "John",
|
56
|
+
last_name: "Doe"
|
57
|
+
}
|
58
|
+
|
59
|
+
products = [
|
60
|
+
{
|
61
|
+
name: "Wireless Mouse for Laptop",
|
62
|
+
unit_price: "15000",
|
63
|
+
quantity: "1"
|
64
|
+
}
|
65
|
+
]
|
66
|
+
|
67
|
+
total_amount = "15000"
|
68
|
+
|
69
|
+
response = PayU.client.place_order(buyer, products, total_amount, meta)
|
70
|
+
|
71
|
+
response.success?
|
72
|
+
#=> true
|
73
|
+
response.order_id
|
74
|
+
#=> "WZHF5FFDRJ140731GUEST000P01"
|
75
|
+
response.ext_order_id
|
76
|
+
#=> "XEGB34325"
|
77
|
+
response.redirect_url
|
78
|
+
#=> # this will return a redirection url to PayU
|
79
|
+
```
|
80
|
+
|
81
|
+
Which will return a `PayU::Orders::Response` object which wraps up everything from the response.
|
82
|
+
|
83
|
+
### Refunding orders
|
84
|
+
|
85
|
+
```
|
86
|
+
order_id = "WZHF5FFDRJ140731GUEST000P01"
|
87
|
+
amount = 15000 # optional
|
88
|
+
|
89
|
+
response = PayU.client.refund_order(order_id, amount = nil)
|
90
|
+
|
91
|
+
response.success?
|
92
|
+
#=> true
|
93
|
+
response.ext_order_id
|
94
|
+
#=> "XEGB34325"
|
95
|
+
response.order_id
|
96
|
+
#=> "WZHF5FFDRJ140731GUEST000P01"
|
97
|
+
```
|
98
|
+
|
99
|
+
### Canceling Orders
|
100
|
+
|
101
|
+
```
|
102
|
+
order_id = "WZHF5FFDRJ140731GUEST000P01"
|
103
|
+
|
104
|
+
response = PayU.client.cancel_order(order_id)
|
105
|
+
|
106
|
+
response.success?
|
107
|
+
#=> true
|
108
|
+
response.ext_order_id
|
109
|
+
#=> "XEGB34325"
|
110
|
+
response.order_id
|
111
|
+
#=> "WZHF5FFDRJ140731GUEST000P01"
|
112
|
+
```
|
113
|
+
|
114
|
+
## Development
|
115
|
+
|
116
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
117
|
+
|
118
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
119
|
+
|
120
|
+
## Testing
|
121
|
+
|
122
|
+
To run RSpec, you need to set up environment variables for PayU. For that, you need to get necessary secrets for a Sandbox account at http://developers.payu.com/en/overview.html.
|
123
|
+
|
124
|
+
After registering your account and creating your test shop, you can then run the tests and add functionality (WRITE THE TESTS).
|
125
|
+
|
126
|
+
Add those to your `bash_profile` or any other environment variables manager of your choice.
|
127
|
+
|
128
|
+
```
|
129
|
+
export PAY_U_POS_ID=<POS_ID>
|
130
|
+
export PAY_U_SECOND_KEY=<SECOND_KEY>
|
131
|
+
export PAY_U_OAUTH_CLIENT_ID=<CLIENT_ID>
|
132
|
+
export PAY_U_OAUTH_CLIENT_SECRET=<CLIENT_SECRET>
|
133
|
+
```
|
134
|
+
|
135
|
+
## Contributing
|
136
|
+
|
137
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/payu.
|
138
|
+
|
139
|
+
## License
|
140
|
+
|
141
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "payu"
|
5
|
+
|
6
|
+
PayU.configure do |c|
|
7
|
+
c.pos_id = ENV['PAY_U_POS_ID']
|
8
|
+
c.second_key = ENV['PAY_U_SECOND_KEY']
|
9
|
+
c.oauth_client_id = ENV['PAY_U_OAUTH_CLIENT_ID']
|
10
|
+
c.oauth_client_secret = ENV['PAY_U_OAUTH_CLIENT_SECRET']
|
11
|
+
c.env = 'sandbox'
|
12
|
+
c.notify_url = 'https://example.com'
|
13
|
+
end
|
14
|
+
|
15
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
16
|
+
# with your gem easier. You can also use a different console, if you like.
|
17
|
+
|
18
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
19
|
+
# require "pry"
|
20
|
+
# Pry.start
|
21
|
+
|
22
|
+
require "irb"
|
23
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
module PayU
|
2
|
+
class BaseRequest
|
3
|
+
def initialize(headers, json_params = {})
|
4
|
+
@headers = headers
|
5
|
+
@keys = []
|
6
|
+
json_params.each_pair do |key, value|
|
7
|
+
@keys << key
|
8
|
+
define_singleton_method(key) do
|
9
|
+
value
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_reader :headers
|
15
|
+
|
16
|
+
def to_h
|
17
|
+
result = {}
|
18
|
+
@keys.each do |key|
|
19
|
+
result.merge!(camelize_key(key, false) => camelized_value(send(key)))
|
20
|
+
end
|
21
|
+
result
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_json
|
25
|
+
to_h.to_json
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def camelized_value(value)
|
31
|
+
if value.respond_to?(:each_pair)
|
32
|
+
camelize_keys(value)
|
33
|
+
elsif value.respond_to?(:each)
|
34
|
+
camelize_array(value)
|
35
|
+
else
|
36
|
+
value
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def camelize_array(array)
|
41
|
+
array.map do |element|
|
42
|
+
camelize_keys(element)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def camelize_keys(hash)
|
47
|
+
camelized_hash = {}
|
48
|
+
hash.each_pair do |key, value|
|
49
|
+
camelized_hash[camelize_key(key, false)] = value
|
50
|
+
end
|
51
|
+
camelized_hash
|
52
|
+
end
|
53
|
+
|
54
|
+
def camelize_key(key, capitalize)
|
55
|
+
index = capitalize ? 0 : 1
|
56
|
+
stringified_key = key.to_s
|
57
|
+
stringified_key.split('_').each_with_index.map do |str, i|
|
58
|
+
index <= i ? str.capitalize : str
|
59
|
+
end.join('').to_sym
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
data/lib/pay_u/client.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'o_auth/authorization'
|
4
|
+
require_relative 'orders/service'
|
5
|
+
require_relative 'base_request'
|
6
|
+
|
7
|
+
module PayU
|
8
|
+
class Client
|
9
|
+
def initialize(configuration, http_client)
|
10
|
+
@configuration = configuration
|
11
|
+
@http_client = http_client
|
12
|
+
end
|
13
|
+
|
14
|
+
def authorize
|
15
|
+
authorization.authorize
|
16
|
+
end
|
17
|
+
|
18
|
+
def place_order(buyer, products, total_amount, meta = {})
|
19
|
+
request_hash = order_meta(meta).merge({ buyer: buyer,
|
20
|
+
products: products,
|
21
|
+
total_amount: total_amount })
|
22
|
+
|
23
|
+
request = PayU::BaseRequest.new(headers, request_hash)
|
24
|
+
orders_service.place_order(request)
|
25
|
+
end
|
26
|
+
|
27
|
+
def refund_order(order_id, amount = nil)
|
28
|
+
request_hash = { refund: { description: "Refund" } }.merge(refund_amount(amount))
|
29
|
+
orders_service.refund_order(order_id, PayU::BaseRequest.new(headers, request_hash))
|
30
|
+
end
|
31
|
+
|
32
|
+
def cancel_order(order_id)
|
33
|
+
orders_service.cancel_order(order_id, PayU::BaseRequest.new(headers))
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def refund_amount(amount)
|
39
|
+
amount.nil? ? {} : { amount: amount }
|
40
|
+
end
|
41
|
+
|
42
|
+
def order_meta(meta)
|
43
|
+
default_order_params.merge(meta)
|
44
|
+
end
|
45
|
+
|
46
|
+
def orders_service
|
47
|
+
@orders_service ||= Orders::Service.new(@http_client)
|
48
|
+
end
|
49
|
+
|
50
|
+
def default_order_params
|
51
|
+
{ notify_url: @configuration.notify_url, merchant_pos_id: @configuration.pos_id }
|
52
|
+
end
|
53
|
+
|
54
|
+
def authorization
|
55
|
+
@authorization ||= OAuth::Authorization.new(@http_client,
|
56
|
+
@configuration.oauth_client_id,
|
57
|
+
@configuration.oauth_client_secret)
|
58
|
+
end
|
59
|
+
|
60
|
+
def headers
|
61
|
+
{ "Authorization" => "Bearer #{authorization.access_token}" }
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module PayU
|
6
|
+
class HttpClient
|
7
|
+
DEFAULT_HEADER = { "Content-Type" => "application/json" }
|
8
|
+
|
9
|
+
def initialize(host)
|
10
|
+
@host = formatted_url(host)
|
11
|
+
end
|
12
|
+
|
13
|
+
def post_form(path, params)
|
14
|
+
response = Net::HTTP.post_form(uri(path), params)
|
15
|
+
parse_json(response.body)
|
16
|
+
end
|
17
|
+
|
18
|
+
def post(path, request)
|
19
|
+
Net::HTTP.post(uri(path), request.to_json, DEFAULT_HEADER.merge(request.headers))
|
20
|
+
end
|
21
|
+
|
22
|
+
def delete(path, request)
|
23
|
+
NET::HTTP.delete(path, DEFAULT_HEADER.merge(request.headers))
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def parse_json(json_string)
|
29
|
+
JSON.parse(json_string)
|
30
|
+
end
|
31
|
+
|
32
|
+
def uri(path)
|
33
|
+
URI(@host + path)
|
34
|
+
end
|
35
|
+
|
36
|
+
def formatted_url(url)
|
37
|
+
url.chomp('/')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require_relative "response"
|
2
|
+
|
3
|
+
module PayU
|
4
|
+
module OAuth
|
5
|
+
class UnauthorizedError < StandardError; end
|
6
|
+
|
7
|
+
class Authorization
|
8
|
+
GRANT_TYPE = "client_credentials"
|
9
|
+
ENDPOINT = "/pl/standard/user/oauth/authorize"
|
10
|
+
|
11
|
+
def initialize(http_client, client_id, client_secret)
|
12
|
+
@http_client = http_client
|
13
|
+
@client_id = client_id
|
14
|
+
@client_secret = client_secret
|
15
|
+
end
|
16
|
+
|
17
|
+
def access_token
|
18
|
+
response = authorize
|
19
|
+
raise UnauthorizedError unless response.success?
|
20
|
+
authorize.access_token
|
21
|
+
end
|
22
|
+
|
23
|
+
def authorize
|
24
|
+
OAuth::Response.new(fetch_response)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def fetch_response
|
30
|
+
@http_client.post_form(ENDPOINT, authorization_options)
|
31
|
+
end
|
32
|
+
|
33
|
+
def authorization_options
|
34
|
+
{ grant_type: GRANT_TYPE, client_id: @client_id, client_secret: @client_secret }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module PayU
|
2
|
+
module OAuth
|
3
|
+
class Response
|
4
|
+
def initialize(response_body)
|
5
|
+
@response_body = response_body
|
6
|
+
end
|
7
|
+
|
8
|
+
def success?
|
9
|
+
@response_body["error"].nil?
|
10
|
+
end
|
11
|
+
|
12
|
+
def access_token
|
13
|
+
@response_body["access_token"]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module PayU
|
4
|
+
module Orders
|
5
|
+
class Response
|
6
|
+
def initialize(response)
|
7
|
+
@response = response
|
8
|
+
@body = JSON.parse(response.body)
|
9
|
+
end
|
10
|
+
|
11
|
+
def code
|
12
|
+
@response.code
|
13
|
+
end
|
14
|
+
|
15
|
+
def success?
|
16
|
+
status.success?
|
17
|
+
end
|
18
|
+
|
19
|
+
def status
|
20
|
+
Status.new(@body['status'])
|
21
|
+
end
|
22
|
+
|
23
|
+
def redirect_url
|
24
|
+
@body['redirectUri']
|
25
|
+
end
|
26
|
+
|
27
|
+
def order_id
|
28
|
+
@body['orderId']
|
29
|
+
end
|
30
|
+
|
31
|
+
def ext_order_id
|
32
|
+
@body['extOrderId']
|
33
|
+
end
|
34
|
+
|
35
|
+
class Status
|
36
|
+
SUCCESS_STATUS = 'SUCCESS'
|
37
|
+
|
38
|
+
def initialize(status)
|
39
|
+
@status = status
|
40
|
+
end
|
41
|
+
|
42
|
+
def success?
|
43
|
+
status_code == SUCCESS_STATUS
|
44
|
+
end
|
45
|
+
|
46
|
+
def status_code
|
47
|
+
@status['statusCode']
|
48
|
+
end
|
49
|
+
|
50
|
+
def code_literal
|
51
|
+
@status['codeLiteral']
|
52
|
+
end
|
53
|
+
|
54
|
+
def code
|
55
|
+
@status['code']
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require_relative 'response'
|
2
|
+
|
3
|
+
module PayU
|
4
|
+
module Orders
|
5
|
+
class Service
|
6
|
+
ENDPOINT = "/api/v2_1/orders"
|
7
|
+
|
8
|
+
def initialize(http_client)
|
9
|
+
@http_client = http_client
|
10
|
+
end
|
11
|
+
|
12
|
+
def place_order(request)
|
13
|
+
Orders::Response.new(
|
14
|
+
@http_client.post(ENDPOINT, request)
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
def refund_order(order_id, request)
|
19
|
+
Orders::Response.new(
|
20
|
+
@http_client.post("#{ENDPOINT}/#{order_id}/refunds", request)
|
21
|
+
)
|
22
|
+
end
|
23
|
+
|
24
|
+
def cancel_order(order_id, request)
|
25
|
+
Orders::Response.new(
|
26
|
+
@http_client.delete("#{ENDPOINT}/#{order_id}", request)
|
27
|
+
)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
data/lib/payu.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require "pay_u/version"
|
2
|
+
require "pay_u/client"
|
3
|
+
require "pay_u/http_client"
|
4
|
+
|
5
|
+
module PayU
|
6
|
+
class Error < StandardError; end
|
7
|
+
|
8
|
+
class << self
|
9
|
+
attr_accessor :configuration, :client
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.configure
|
13
|
+
self.configuration ||= Configuration.new
|
14
|
+
yield(configuration)
|
15
|
+
self.client = Client.new(configuration, HttpClient.new(configuration.host))
|
16
|
+
end
|
17
|
+
|
18
|
+
class Configuration
|
19
|
+
PRODUCTION_ENV_NAME = "production"
|
20
|
+
SANDBOX_HOST_URI = "https://secure.snd.payu.com/"
|
21
|
+
PRODUCTION_HOST_URI = "https://secure.payu.com/"
|
22
|
+
|
23
|
+
attr_accessor :pos_id, :second_key, :oauth_client_id, :oauth_client_secret, :env, :notify_url
|
24
|
+
|
25
|
+
def initialize
|
26
|
+
@env = PRODUCTION_ENV_NAME
|
27
|
+
end
|
28
|
+
|
29
|
+
def host
|
30
|
+
production? ? PRODUCTION_HOST_URI : SANDBOX_HOST_URI
|
31
|
+
end
|
32
|
+
|
33
|
+
def production?
|
34
|
+
@env == PRODUCTION_ENV_NAME
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
data/payu.gemspec
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "pay_u/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "pay_u"
|
8
|
+
spec.version = PayU::VERSION
|
9
|
+
spec.authors = ["michal.kosyk"]
|
10
|
+
spec.email = ["michal.kosyk@naturaily.com"]
|
11
|
+
|
12
|
+
spec.summary = "PayU client"
|
13
|
+
spec.description = "PayU API client"
|
14
|
+
spec.homepage = "https://naturaily.eu"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
# spec.metadata["allowed_push_host"] = "'http://mygemserver.com'"
|
21
|
+
|
22
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
23
|
+
spec.metadata["source_code_uri"] = "https://naturaily.eu"
|
24
|
+
spec.metadata["changelog_uri"] = "https://naturaily.eu"
|
25
|
+
else
|
26
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
27
|
+
"public gem pushes."
|
28
|
+
end
|
29
|
+
|
30
|
+
# Specify which files should be added to the gem when it is released.
|
31
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
32
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
33
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
34
|
+
end
|
35
|
+
spec.bindir = "exe"
|
36
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
37
|
+
spec.require_paths = ["lib"]
|
38
|
+
|
39
|
+
spec.add_development_dependency "bundler", "~> 1.17"
|
40
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
41
|
+
spec.add_development_dependency "pry", '~> 0'
|
42
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
43
|
+
end
|
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pay_u
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- michal.kosyk
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-01-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.17'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.17'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
description: PayU API client
|
70
|
+
email:
|
71
|
+
- michal.kosyk@naturaily.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".travis.yml"
|
79
|
+
- Gemfile
|
80
|
+
- Gemfile.lock
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/console
|
85
|
+
- bin/setup
|
86
|
+
- lib/pay_u/base_request.rb
|
87
|
+
- lib/pay_u/client.rb
|
88
|
+
- lib/pay_u/http_client.rb
|
89
|
+
- lib/pay_u/o_auth/authorization.rb
|
90
|
+
- lib/pay_u/o_auth/response.rb
|
91
|
+
- lib/pay_u/orders/response.rb
|
92
|
+
- lib/pay_u/orders/service.rb
|
93
|
+
- lib/pay_u/version.rb
|
94
|
+
- lib/payu.rb
|
95
|
+
- payu.gemspec
|
96
|
+
homepage: https://naturaily.eu
|
97
|
+
licenses:
|
98
|
+
- MIT
|
99
|
+
metadata:
|
100
|
+
homepage_uri: https://naturaily.eu
|
101
|
+
source_code_uri: https://naturaily.eu
|
102
|
+
changelog_uri: https://naturaily.eu
|
103
|
+
post_install_message:
|
104
|
+
rdoc_options: []
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
requirements: []
|
118
|
+
rubyforge_project:
|
119
|
+
rubygems_version: 2.7.6
|
120
|
+
signing_key:
|
121
|
+
specification_version: 4
|
122
|
+
summary: PayU client
|
123
|
+
test_files: []
|