elements-pay 1.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7b47abd86699fc6853689e4cd3063d67d639956fa0d7c5975cd18710adc748b0
4
+ data.tar.gz: 881405689ed69b828eec05919293cd374e381ec6ec80e0f914e268e31c221656
5
+ SHA512:
6
+ metadata.gz: 717b8a25084bf9ad7aa2080fad21d34b88c07798575feb8ef73fb1d71e71ae010c536e7caa138863b6ce2eb676d172b93d0f20dc9d2b6f4d02cc67ee786a0c6d
7
+ data.tar.gz: 7b0e83fa3ddd3a9ed5cb8e64ee2df5e3df8c5d0eefe4250fcd64f410919442064cdbab42fd257a81d70c84ffc2c9327329dd0c88a1d6244e5b345cc1fa3d7920
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ elements-ruby-sdk
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.7.2
data/Gemfile ADDED
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ gemspec
8
+
9
+ group :development, :test do
10
+ gem 'rake'
11
+ gem 'rspec'
12
+ gem 'webmock'
13
+
14
+ gem 'byebug'
15
+ gem 'pry'
16
+ gem 'pry-byebug'
17
+
18
+ gem 'rubocop'
19
+ end
data/README.md ADDED
@@ -0,0 +1,123 @@
1
+ # Elements Ruby SDK
2
+
3
+ Ruby bindings for the Elements API.
4
+
5
+ ## Installation
6
+
7
+ You may install the gem from Github Packages.
8
+
9
+ First, you must authenticate yourself to Github Packages by creating a personal access token.
10
+ You may do that in Github Settings > Developer settings > Personal access tokens. Please follow the instructions [here](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-rubygems-registry#authenticating-to-github-packages).
11
+
12
+ Then add the following to your Gemfile.
13
+
14
+ ```ruby
15
+ source 'https://rubygems.pkg.github.com/elementspay' do
16
+ gem 'elements-pay', '>= 0.0.3'
17
+ end
18
+ ```
19
+
20
+ Build the gem from source:
21
+
22
+ ```bash
23
+ $ gem build elements-pay.gemspec
24
+ ```
25
+
26
+ ## Configuration
27
+
28
+ This library requires you to configure the API key:
29
+
30
+ ```ruby
31
+ require "elements"
32
+
33
+ Elements.configure do |c|
34
+ # You must set a valid api key
35
+ c.api_key = "my_api_key"
36
+ # Optionally, you can configure logging for request & response
37
+ c.logger = Logger.new($stdout)
38
+ end
39
+ ```
40
+
41
+ If you want to connect to the sandbox instead of production, you may configure the `api_base` to use the sandbox url:
42
+
43
+ ```ruby
44
+ require "elements"
45
+
46
+ Elements.configure do |c|
47
+ c.api_base = Elements::ElementsConfiguration::SANDBOX_URL
48
+ end
49
+ ```
50
+
51
+ ## Usage
52
+
53
+ ```ruby
54
+ require "elements"
55
+
56
+ # To create an authorized charge
57
+ authorized_charge = Elements::Charge.create({
58
+ amount: 30000,
59
+ currency: "USD",
60
+ payment_method_id: "PM-XXXXXX"
61
+ })
62
+
63
+ # Access model attributes like object fields
64
+
65
+ authorized_charge.amount # 30000
66
+ authorized_charge.currency # "USD"
67
+ authorized_charge.captured? # false
68
+
69
+ # To capture the charge
70
+ captured_charge = Elements::Charge.capture(authorized_charge.id,
71
+ { amount: 30000 })
72
+
73
+ # To obtain a client token
74
+ client_token = Elements::ClientToken.create({ external_customer_id: "foo" })
75
+
76
+ # To retrieve payment method
77
+ payment_method = Elements::PaymentMethod.retrieve({
78
+ payment_method_id: "PM-XXXXXX",
79
+ external_customer_id: "foo"
80
+ })
81
+ ```
82
+
83
+ Please refer to our REST API docs for detailed API usage information.
84
+
85
+ ## Contribute
86
+
87
+ Begin by cloning the repository on GitHub.
88
+
89
+ ```bash
90
+ $ git clone git@github.com:elementspay/elements-ruby-sdk.git
91
+ $ cd elements-ruby-sdk
92
+ ```
93
+
94
+ You may then create your changes and issue pull requests.
95
+
96
+ ### Test your changes
97
+
98
+ It is encouraged to test your changes using RSpec and mocks, but if you want to perform some adhoc testing,
99
+ you may do so with a REPL like IRB. You may also run `./bin/elements-console` to launch the IRB session,
100
+ this executable also includes Elements lib as a dependency for you automatically.
101
+
102
+ By default, the SDK connects to the production Elements API. You may test your changes with a local or a sandbox environment, by configuring the proper
103
+ `api_base` and `api_key`:
104
+
105
+ ```ruby
106
+ require "elements"
107
+
108
+ Elements.configure do |c|
109
+ c.api_base = "http://localhost:3000"
110
+ c.api_key = "my local api key"
111
+ end
112
+ ```
113
+
114
+ ## Release
115
+
116
+ First, bump the version number in `lib/elements/version.rb`, following the format of `major.minor.patch`
117
+
118
+ Then create a pull request and have the version bump merged into master.
119
+
120
+ After the master has been updated, check out a new tag according to the new version, say the new version is 1.6.7, then
121
+ you should create a new tag called `v1.6.7` and push that to remote.
122
+
123
+ Once the tag has been pushed, Github action will launch the `.github/workflows/publish.yml`, and you should watch for progress in https://github.com/elementspay/elements-ruby-sdk/actions.
data/Rakefile ADDED
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ task default: %i[spec lint]
4
+
5
+ begin
6
+ require 'rubocop/rake_task'
7
+
8
+ RuboCop::RakeTask.new(:lint) do |t|
9
+ t.fail_on_error = true
10
+ end
11
+ rescue LoadError
12
+ # no rubocop available
13
+ end
14
+
15
+ begin
16
+ require 'rspec/core/rake_task'
17
+
18
+ RSpec::Core::RakeTask.new(:spec) do |t|
19
+ t.fail_on_error = true
20
+ end
21
+ rescue LoadError
22
+ # no rspec available
23
+ end
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # frozen_string_literal: true
4
+
5
+ $LOAD_PATH.unshift File.expand_path('../lib/', __dir__)
6
+
7
+ require 'irb'
8
+ require 'irb/completion'
9
+ require 'logger'
10
+ require 'elements'
11
+
12
+ Elements.configure do |c|
13
+ c.logger = Logger.new($stdout)
14
+ end
15
+
16
+ IRB.conf[:PROMPT_MODE] = :SIMPLE
17
+ IRB.conf[:AUTO_INDENT] = true
18
+ IRB.start
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.unshift(::File.join(::File.dirname(__FILE__), 'lib'))
4
+
5
+ require 'elements/version'
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = 'elements-pay'
9
+ s.version = Elements::VERSION
10
+ s.summary = 'The Elements Ruby SDK'
11
+ s.description = 'Ruby bindings for the Elements API'
12
+ s.author = 'Elements'
13
+ s.email = 'help@elements.io'
14
+ s.homepage = 'https://elements.io'
15
+ s.license = 'MIT'
16
+ s.metadata = {
17
+ 'github_repo' => 'git@github.com:elementspay/elements-ruby-sdk.git',
18
+ 'bug_tracker_uri' => 'https://github.com/elementspay/elements-ruby-sdk/issues',
19
+ 'source_code_uri' => 'https://github.com/elementspay/elements-ruby-sdk'
20
+ }
21
+
22
+ ignored = Regexp.union(
23
+ /\A\.git/,
24
+ /\A\.rubocop/,
25
+ /\A\.git/,
26
+ /\Aspec/
27
+ )
28
+
29
+ s.files = `git ls-files`.split("\n").reject { |f| ignored.match(f) }
30
+ s.require_paths = ['lib']
31
+ s.add_dependency 'addressable', '~> 2.5'
32
+ s.add_dependency 'rest-client', '~> 2.0', '>= 2.0.1'
33
+ end