smartpay 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 47818556e63df74af8fe9b541af5da55382239b5269db1b7f120283a5f9de904
4
- data.tar.gz: f79f51a7c3957d78b3f739ea1134a132ae4fc5b3c20bafed6621270621c8a57d
3
+ metadata.gz: 38d6c56f2c6abb2cf337532c6e3d10943111aed67b585d62c5fb6bdc1ab26198
4
+ data.tar.gz: 8f67b047ab3bfb8cc28c503657ea3f02bb83f6cab0fd25ce04ca9eab90853bb2
5
5
  SHA512:
6
- metadata.gz: 76b19f63d6e0e4663fed1f3a060577569c9a19e4f8a35e01c4485e41c51ea30683242f96aa3367d672a2e75dd762b621f65c74456a7339e601c6ab727ef37755
7
- data.tar.gz: d99f4a71d2a3471c7c1f4ad9202a2c5b06b4492838779e84c7f316dbfbefbe6c58639ef7cfd1245f49dbd1cbb0ef7b953ed8b62e1afeb46145fe561174d48c3f
6
+ metadata.gz: 87a360308fd0f6d5b5ec8cb73c28f611c03ae465ccb16bd5fc53d989812e95b84e1873890fa011fd27adde18d3f953c1974a26499f4b5beae36b4c79db6aa25b
7
+ data.tar.gz: 020bc848c1ddb5bfe842bac6e78b622cde388fcd33de9719f5e877a2583e2b47aaa733c0e626d7aa7a8e41c35d7fc945feef9b1c02bd95eadc217211c7cd96ea
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Smartpay
4
+ class Api
5
+ class << self
6
+ def create_checkout_session(payload)
7
+ Responses::CheckoutSession.new(Client.post('/checkout/sessions', payload))
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Smartpay
4
+ class Client
5
+ class << self
6
+ def post(path, payload = {})
7
+ response = RestClient::Request.execute(method: :post, url: api_url(path), headers: headers, timeout: timeout, payload: payload.to_json)
8
+ JSON.parse(response.body, symbolize_names: true)
9
+ end
10
+
11
+ private
12
+
13
+ def api_url(path)
14
+ "#{Smartpay.configuration.api_url}#{path}"
15
+ end
16
+
17
+ def timeout
18
+ Smartpay.configuration.post_timeout
19
+ end
20
+
21
+ def headers
22
+ {
23
+ accept: :json,
24
+ content_type: :json,
25
+ Authorization: "Basic #{api_secret}"
26
+ }
27
+ end
28
+
29
+ def api_secret
30
+ Smartpay.configuration.api_secret
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Smartpay
4
+ class Configuration
5
+ attr_accessor :post_timeout
6
+ attr_accessor :public_key, :api_secret, :api_url, :checkout_url
7
+
8
+ DEFAULT_TIMEOUT_SETTING = 30
9
+ DEFAULT_API_URL = 'https://api.smartpay.co'
10
+ DEFAULT_CHECKOUT_URL = 'https://checkout.smartpay.co'
11
+
12
+ def initialize
13
+ @post_timeout = DEFAULT_TIMEOUT_SETTING
14
+ @api_url = DEFAULT_API_URL
15
+ @checkout_url = DEFAULT_CHECKOUT_URL
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Smartpay
4
+ module Responses
5
+ class CheckoutSession
6
+ attr_reader :response
7
+
8
+ def initialize(response)
9
+ @response = response
10
+ end
11
+
12
+ def redirect_url
13
+ URI.escape("#{checkout_url}/login?session-id=#{response[:id]}&public-key=#{public_key}")
14
+ end
15
+
16
+ private
17
+
18
+ def checkout_url
19
+ Smartpay.configuration.checkout_url
20
+ end
21
+
22
+ def public_key
23
+ Smartpay.configuration.public_key
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Smartpay
4
- VERSION = "0.0.1"
4
+ VERSION = "0.1.0"
5
5
  end
data/lib/smartpay.rb CHANGED
@@ -1,8 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'json'
4
+
3
5
  require_relative "smartpay/version"
6
+ require_relative 'smartpay/configuration'
7
+ require_relative 'smartpay/client'
8
+ require_relative 'smartpay/api'
9
+ require_relative 'smartpay/responses/checkout_session'
4
10
 
5
11
  module Smartpay
6
- class Error < StandardError; end
7
- # Your code goes here...
12
+ class << self
13
+ attr_accessor :configuration
14
+
15
+ def configuration
16
+ @configuration ||= Smartpay::Configuration.new
17
+ end
18
+
19
+ def configure
20
+ yield(configuration)
21
+ end
22
+ end
8
23
  end
metadata CHANGED
@@ -1,16 +1,44 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smartpay
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Smartpay
8
- autorequire:
9
- bindir: exe
8
+ autorequire:
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-05 00:00:00.000000000 Z
12
- dependencies: []
13
- description:
11
+ date: 2021-10-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ description:
14
42
  email:
15
43
  - uxe@smartpay.co
16
44
  executables: []
@@ -28,6 +56,10 @@ files:
28
56
  - bin/console
29
57
  - bin/setup
30
58
  - lib/smartpay.rb
59
+ - lib/smartpay/api.rb
60
+ - lib/smartpay/client.rb
61
+ - lib/smartpay/configuration.rb
62
+ - lib/smartpay/responses/checkout_session.rb
31
63
  - lib/smartpay/version.rb
32
64
  homepage: https://smartpay.co
33
65
  licenses:
@@ -36,7 +68,7 @@ metadata:
36
68
  homepage_uri: https://smartpay.co
37
69
  source_code_uri: https://github.com/smartpay-co/sdk-ruby
38
70
  changelog_uri: https://github.com/smartpay-co/sdk-ruby/blob/main/CHANGELOG.md
39
- post_install_message:
71
+ post_install_message:
40
72
  rdoc_options: []
41
73
  require_paths:
42
74
  - lib
@@ -51,8 +83,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
51
83
  - !ruby/object:Gem::Version
52
84
  version: '0'
53
85
  requirements: []
54
- rubygems_version: 3.2.28
55
- signing_key:
86
+ rubygems_version: 3.0.3
87
+ signing_key:
56
88
  specification_version: 4
57
89
  summary: The Smartpay Ruby SDK offers easy access to Smartpay API from applications
58
90
  written in Ruby.