kraken_pay 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 +7 -0
- data/.rspec +3 -0
- data/CHANGELOG.md +9 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +56 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +8 -0
- data/bin/console +43 -0
- data/bin/setup +8 -0
- data/kraken_pay.gem +0 -0
- data/lib/kraken_pay/api_error.rb +40 -0
- data/lib/kraken_pay/client.rb +60 -0
- data/lib/kraken_pay/configuration.rb +29 -0
- data/lib/kraken_pay/http_status_codes.rb +15 -0
- data/lib/kraken_pay/version.rb +5 -0
- data/lib/kraken_pay.rb +30 -0
- data/sig/kraken_pay.rbs +4 -0
- metadata +108 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8ff36897177480b0149ac91dcce6c0221820e9ffccce6e464ae1b96577d1265f
|
4
|
+
data.tar.gz: c1c2ceda50ae5cbac5b807cfc0e70c2e7352b6de0eb3858b395008ecb3da35a5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bc818a4b6357dffa54834e5a421969fdbd4318842804ea8f731851fa5a8ed2d69951a13fa8646d7a38a407c34f104c60eddb975feb1ccfeb1d2bcbb5ee24fc87
|
7
|
+
data.tar.gz: 98101377f368ada2b3b4d6a7749c56a8af426aaafdfcf71efeb007eec5efec2316adb09b5b740e498fb18ac04c0faebc9fb455f0e5ba5ddb461cb7b46e056ba2
|
data/.rspec
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
kraken_pay (0.2.0)
|
5
|
+
httparty
|
6
|
+
oj
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
bigdecimal (3.1.9)
|
12
|
+
coderay (1.1.3)
|
13
|
+
csv (3.3.2)
|
14
|
+
diff-lcs (1.5.0)
|
15
|
+
httparty (0.22.0)
|
16
|
+
csv
|
17
|
+
mini_mime (>= 1.0.0)
|
18
|
+
multi_xml (>= 0.5.2)
|
19
|
+
method_source (1.0.0)
|
20
|
+
mini_mime (1.1.5)
|
21
|
+
multi_xml (0.7.1)
|
22
|
+
bigdecimal (~> 3.1)
|
23
|
+
oj (3.16.9)
|
24
|
+
bigdecimal (>= 3.0)
|
25
|
+
ostruct (>= 0.2)
|
26
|
+
ostruct (0.6.1)
|
27
|
+
pry (0.14.1)
|
28
|
+
coderay (~> 1.1)
|
29
|
+
method_source (~> 1.0)
|
30
|
+
rake (13.0.6)
|
31
|
+
rspec (3.12.0)
|
32
|
+
rspec-core (~> 3.12.0)
|
33
|
+
rspec-expectations (~> 3.12.0)
|
34
|
+
rspec-mocks (~> 3.12.0)
|
35
|
+
rspec-core (3.12.0)
|
36
|
+
rspec-support (~> 3.12.0)
|
37
|
+
rspec-expectations (3.12.0)
|
38
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
39
|
+
rspec-support (~> 3.12.0)
|
40
|
+
rspec-mocks (3.12.0)
|
41
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
42
|
+
rspec-support (~> 3.12.0)
|
43
|
+
rspec-support (3.12.0)
|
44
|
+
|
45
|
+
PLATFORMS
|
46
|
+
arm64-darwin-22
|
47
|
+
x86_64-darwin-20
|
48
|
+
|
49
|
+
DEPENDENCIES
|
50
|
+
kraken_pay!
|
51
|
+
pry
|
52
|
+
rake (~> 13.0)
|
53
|
+
rspec (~> 3.0)
|
54
|
+
|
55
|
+
BUNDLED WITH
|
56
|
+
2.2.33
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022 Exequiel Rozas
|
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,39 @@
|
|
1
|
+
# KrakenPay
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/kraken_pay`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'kraken_pay'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install kraken_pay
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
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.
|
30
|
+
|
31
|
+
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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/kraken_pay.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
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,43 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'kraken_pay'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
KrakenPay.configure do |config|
|
15
|
+
config.api_endpoint = 'https://pagos.kraken.bo:8443/api/payments'
|
16
|
+
config.affiliate_code = '617ec678-1e0c-4813-97dc-f4fc0c4c7290'
|
17
|
+
end
|
18
|
+
|
19
|
+
params = { affiliateCode: '617ec678-1e0c-4813-97dc-f4fc0c4c7290',
|
20
|
+
withInvoice: false,
|
21
|
+
expireMinutes: 6320,
|
22
|
+
externalCode: '4adee5849f',
|
23
|
+
paymentDescription: 'Pago correspondiente al pedido 4adee5849f',
|
24
|
+
details: [{ concept: 'Matisse Castrados Salmón - 2 kg',
|
25
|
+
productImageUrl: 'https://d34xtejqjqcp3x.cloudfront.net/store/2d4a8fea77d0b5898fa2f583b3de160c.png',
|
26
|
+
quantity: 1,
|
27
|
+
unitPrice: 0.86e2,
|
28
|
+
sequence: 2 },
|
29
|
+
{ concept: 'Canada Litter Multicat - 18 kg',
|
30
|
+
productImageUrl: 'https://d34xtejqjqcp3x.cloudfront.net/store/46de03b8d80d5970f7f64a10482f1393.webp',
|
31
|
+
quantity: 1,
|
32
|
+
unitPrice: 0.197e3,
|
33
|
+
sequence: 2 },
|
34
|
+
{ concept: 'Peluche Zorro M-Pets - Rosa',
|
35
|
+
productImageUrl: 'https://d34xtejqjqcp3x.cloudfront.net/store/9deb1d16932ff6cb579e618dce618f52.webp',
|
36
|
+
quantity: 1,
|
37
|
+
unitPrice: 0.22e2,
|
38
|
+
sequence: 2 }] }
|
39
|
+
|
40
|
+
client = KrakenPay::Client.new
|
41
|
+
|
42
|
+
require 'irb'
|
43
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/kraken_pay.gem
ADDED
Binary file
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module KrakenPay
|
2
|
+
class ApiError < StandardError
|
3
|
+
attr_accessor :response, :code
|
4
|
+
attr_reader :http_body, :http_headers, :message
|
5
|
+
|
6
|
+
def initialize(message = nil, http_body = nil, _http_headers = nil)
|
7
|
+
@message = message
|
8
|
+
@http_body = http_body
|
9
|
+
@http_headers = http_headers
|
10
|
+
end
|
11
|
+
|
12
|
+
# It should be raised when the API call returns a 400 Error Code
|
13
|
+
class BadRequestError < ApiError
|
14
|
+
end
|
15
|
+
|
16
|
+
# It should be raised when the API call returns a 401 Error Code
|
17
|
+
class UnauthorizedError < ApiError
|
18
|
+
end
|
19
|
+
|
20
|
+
# It should be raised when the API call returns a 403 Error Code
|
21
|
+
class ForbiddenError < ApiError
|
22
|
+
end
|
23
|
+
|
24
|
+
# It should be raised when the API call returns a 404 Error Code
|
25
|
+
class NotFoundError < ApiError
|
26
|
+
end
|
27
|
+
|
28
|
+
# It should be raised when the API call returns a 422 Error Code
|
29
|
+
class UnprocessableEntityError < ApiError
|
30
|
+
end
|
31
|
+
|
32
|
+
# It should be raised when the API call returns a 429 Error Code
|
33
|
+
class TooManyRequestsError < ApiError
|
34
|
+
end
|
35
|
+
|
36
|
+
# It should be raised when the API call returns 500 error
|
37
|
+
class InternalServerError < ApiError
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'httparty'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
module KrakenPay
|
7
|
+
class Client
|
8
|
+
attr_reader :affiliate_code
|
9
|
+
|
10
|
+
BASE_URL = KrakenPay.configuration.api_endpoint
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@affiliate_code = KrakenPay.configuration.affiliate_code
|
14
|
+
end
|
15
|
+
|
16
|
+
def generate_qr_payment(params)
|
17
|
+
response = HTTParty.post("#{BASE_URL}/process/simple", body: params.to_json, headers: default_headers)
|
18
|
+
end
|
19
|
+
|
20
|
+
def register_transaction(params)
|
21
|
+
response = HTTParty.post("#{BASE_URL}/transaction", body: params.to_json, headers: default_headers)
|
22
|
+
handle_response(response)
|
23
|
+
end
|
24
|
+
|
25
|
+
def check_qr_payment_status(payment_id, transaction_id)
|
26
|
+
response = HTTParty.get("#{BASE_URL}/status/simple/#{payment_id}/#{transaction_id}", headers: default_headers)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def default_headers
|
32
|
+
{ 'Content-Type' => 'application/json', 'Accept' => '*/*', 'Accept-Encoding' => 'gzip, deflate, br' }
|
33
|
+
end
|
34
|
+
|
35
|
+
# Because of the way the API works: it doesn't return a status code for successfull requests
|
36
|
+
# We need to handle errors conditionally. If the response doesn't have a status code, it means
|
37
|
+
# That it was successfull. If it does, it means there was an error
|
38
|
+
def handle_response(response)
|
39
|
+
parsed = JSON.parse(response.body)
|
40
|
+
return parsed unless parsed['status']
|
41
|
+
|
42
|
+
case parsed['status']
|
43
|
+
when 400
|
44
|
+
raise ApiError::BadRequestError, parsed['detail']
|
45
|
+
when 401
|
46
|
+
raise ApiError::UnauthorizedError, parsed['detail']
|
47
|
+
when 403
|
48
|
+
raise ApiError::ForbiddenError, parsed['detail']
|
49
|
+
when 404
|
50
|
+
raise ApiError::NotFoundError, parsed['detail']
|
51
|
+
when 422
|
52
|
+
raise ApiError::UnprocessableEntityError, parsed['detail']
|
53
|
+
when 429
|
54
|
+
raise ApiError::TooManyRequestsError, parsed['detail']
|
55
|
+
when 500
|
56
|
+
raise ApiError::InternalServerError, parsed['detail']
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module KrakenPay
|
2
|
+
class Configuration
|
3
|
+
# The endpoint that this gem will use to interact with the API
|
4
|
+
# defaults to: nil
|
5
|
+
# @return [String]
|
6
|
+
attr_accessor :api_endpoint
|
7
|
+
|
8
|
+
# The code that identifies the merchant with Kraken
|
9
|
+
# defaults to: nil
|
10
|
+
# @return [String]
|
11
|
+
attr_accessor :affiliate_code
|
12
|
+
|
13
|
+
# The username used to identify our account with Kraken
|
14
|
+
# defaults to: nil
|
15
|
+
# @return [String]
|
16
|
+
attr_accessor :username
|
17
|
+
|
18
|
+
# The password used to corroborate our identity with Kraken
|
19
|
+
# defaults to: nil
|
20
|
+
# @return [String]
|
21
|
+
|
22
|
+
def initialize
|
23
|
+
@api_endpoint = nil
|
24
|
+
@affiliate_code = nil
|
25
|
+
@username = nil
|
26
|
+
@password = nil
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module KrakenInvoicing
|
2
|
+
module HttpStatusCodes
|
3
|
+
HTTP_OK_CODE = 200
|
4
|
+
HTTP_CREATED_CODE = 201
|
5
|
+
|
6
|
+
HTTP_BAD_REQUEST_CODE = 400
|
7
|
+
HTTP_UNAUTHORIZED_CODE = 401
|
8
|
+
HTTP_FORBIDDEN_CODE = 403
|
9
|
+
HTTP_NOT_FOUND_CODE = 404
|
10
|
+
HTTP_UNPROCESSABLE_ENTITY_CODE = 422
|
11
|
+
HTTP_TOO_MANY_REQUESTS = 429
|
12
|
+
|
13
|
+
HTTP_INTERNAL_SERVER_ERROR = 500
|
14
|
+
end
|
15
|
+
end
|
data/lib/kraken_pay.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'kraken_pay/version'
|
4
|
+
|
5
|
+
module KrakenPay
|
6
|
+
autoload :ApiError, 'kraken_pay/api_error'
|
7
|
+
autoload :Client, 'kraken_pay/client'
|
8
|
+
autoload :Configuration, 'kraken_pay/configuration'
|
9
|
+
autoload :HttpStatusCodes, 'kraken_pay/http_status_codes'
|
10
|
+
autoload :Resource, 'kraken_pay/resource'
|
11
|
+
|
12
|
+
autoload :Transaction, 'kraken_pay/resources/transaction'
|
13
|
+
|
14
|
+
autoload :BadRequestError, 'kraken_pay/api_error'
|
15
|
+
autoload :NotFoundError, 'kraken_pay/api_error'
|
16
|
+
autoload :InternalServerError, 'kraken_pay/api_error'
|
17
|
+
autoload :UnauthorizedError, 'kraken_pay/api_error'
|
18
|
+
autoload :ForbiddenError, 'kraken_pay/api_error'
|
19
|
+
autoload :TooManyRequestsError, 'kraken_pay/api_error'
|
20
|
+
autoload :UnprocessableEntityError, 'kraken_pay/api_error'
|
21
|
+
|
22
|
+
class << self
|
23
|
+
attr_accessor :configuration
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.configure
|
27
|
+
self.configuration ||= Configuration.new
|
28
|
+
yield(configuration)
|
29
|
+
end
|
30
|
+
end
|
data/sig/kraken_pay.rbs
ADDED
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kraken_pay
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Exequiel Rozas
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2025-02-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pry
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: httparty
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: oj
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Kraken Pay es una gema para interactuar con la API de pagos de Kraken
|
56
|
+
Bolivia que permite generar pagos usando la pasarela de pagos de Kraken y también
|
57
|
+
pagos con código QR
|
58
|
+
email:
|
59
|
+
- exequiel98@gmail.com
|
60
|
+
executables: []
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- ".rspec"
|
65
|
+
- CHANGELOG.md
|
66
|
+
- Gemfile
|
67
|
+
- Gemfile.lock
|
68
|
+
- LICENSE.txt
|
69
|
+
- README.md
|
70
|
+
- Rakefile
|
71
|
+
- bin/console
|
72
|
+
- bin/setup
|
73
|
+
- kraken_pay.gem
|
74
|
+
- lib/kraken_pay.rb
|
75
|
+
- lib/kraken_pay/api_error.rb
|
76
|
+
- lib/kraken_pay/client.rb
|
77
|
+
- lib/kraken_pay/configuration.rb
|
78
|
+
- lib/kraken_pay/http_status_codes.rb
|
79
|
+
- lib/kraken_pay/version.rb
|
80
|
+
- sig/kraken_pay.rbs
|
81
|
+
homepage: https://github.com/petservi/kraken_pay
|
82
|
+
licenses:
|
83
|
+
- MIT
|
84
|
+
metadata:
|
85
|
+
allowed_push_host: https://rubygems.org
|
86
|
+
homepage_uri: https://github.com/petservi/kraken_pay
|
87
|
+
source_code_uri: https://github.com/erozas/kraken_pay
|
88
|
+
changelog_uri: https://github.com/erozas/kraken_pay
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: 2.6.0
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
requirements: []
|
104
|
+
rubygems_version: 3.5.4
|
105
|
+
signing_key:
|
106
|
+
specification_version: 4
|
107
|
+
summary: Kraken Pay es una gema para interactuar con la API de pagos de Kraken Bolivia
|
108
|
+
test_files: []
|