coinbase_commerce_client 0.2.0 → 0.4.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b9a510d1becec57136692c56a98c2de295de90368ef7f293f8d0cc4bba601a45
4
- data.tar.gz: 8e2c35f74a5414449ff9a8df15a69dc87609c94f60d93e502943f38403e2d598
3
+ metadata.gz: 1dffeec59ae055d348576c580c7d368d08f1e6cfa83eff0df98654bedc37f10c
4
+ data.tar.gz: b259d64a1f5acecbf1c1ba596d9dc81851a5f7ad95518e2978dccc372afe31fa
5
5
  SHA512:
6
- metadata.gz: 3f1e618708f0b31d5016eb4635e067e64c5e28cc8dbe8aa1c81748092c18ce4e4956edc1b54ee9465adcc1dcd47ffb8303757c16b13ea0eea8cd32ac39b46071
7
- data.tar.gz: d6c11deb7cb8a95030e3fe8cd1277d98bcc6b26ae44a38dcf53bde5ca7f4e505d8e2169335ed0e1d5de5a580a5f433d5e2612dbeda66e2e498233693ca32039d
6
+ metadata.gz: 36af3d120360de81dfbb33d60cbdfcce9dd06710e40e7d797d9ef04e85e1693757ae10e73a8bb768131b10e620aad992a87242eff16c73e1978fcb992680e86d
7
+ data.tar.gz: 45fe372fb55aa69c0041bca0072745558ca2f9807a0e51b3b13764834d9b14f8df5605ef1a531ca561ae2ef698d3b83b5e82838e999311600b80ef194a09dd2d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- coinbase_commerce_client (0.2.0)
4
+ coinbase_commerce_client (0.4.2)
5
5
  faraday (~> 2.6)
6
6
  multipart-post (~> 2.0)
7
7
 
data/README.md CHANGED
@@ -1,32 +1,34 @@
1
- [![Coverage](badge.svg)](https://github.com/viniciusborgeis/coinbase_commerce_client)
2
- <p>
3
- <img width="100%" src="https://raw.githubusercontent.com/viniciusborgeis/coinbase_commerce_client/main/assets/banner.png" alt="Solid Vite Templates">
1
+ <h1 align="center">
2
+ <br>
3
+ <img width="100%" src="https://raw.githubusercontent.com/viniciusborgeis/coinbase_commerce_client/main/assets/banner.png" alt="Coinbase Commerce Client">
4
+ <br>
5
+ Coinbase Commerce Client
6
+ <br>
7
+ </h1>
8
+
9
+ <h4 align="center">A client to handle cryptocurrency payments using <a href="https://commerce.coinbase.com/" target="_blank">Coinbase Commerce</a> platform</h4>
10
+
11
+ <p align="center">
12
+ <img src="https://badge.fury.io/rb/coinbase_commerce_client.svg" alt="Coverage">
13
+ <img src="https://raw.githubusercontent.com/viniciusborgeis/coinbase_commerce_client/main/badge.svg" alt="Coverage">
14
+ <img src="https://img.shields.io/gem/dt/coinbase_commerce_client.svg?type=total" alt="Total Downloads">
4
15
  </p>
5
16
 
6
- # Coinbase Commerce Client
7
- > <sub>This gem is completely inspired by official Coinbase gem [coinbase-commerce-ruby](https://github.com/coinbase/coinbase-commerce-ruby), unfortunately the oficial gem actually is deprecated, and my motivation is to continue support for this gem</sub>
8
-
9
- Coinbase Commerce Client Ruby Gem
10
-
11
- # Table of contents
12
-
13
- <!--ts-->
14
- * [Ruby Versions](#ruby-version)
15
- * [Third Party Libraries and Dependencies](#third-party-libraries-and-dependencies)
16
- * [Documentation](#documentation)
17
- * [Installation](#installation)
18
- * [Usage](#usage)
19
- * [Checkouts](#checkouts)
20
- * [Charges](#charges)
21
- * [Events](#events)
22
- * [Validating webhook signatures](#validating-webhook-signatures)
23
- * [Testing and Contributing](#testing-and-contributing)
24
- <!--te-->
17
+ <p align="center">
18
+ <a href="#ruby-version">Ruby Versions</a>
19
+ <a href="#dependencies">Dependencies</a> •
20
+ <a href="#documentation">Docs</a>
21
+ <a href="#installation">Installation</a> •
22
+ <a href="#usage">Usage</a>
23
+ <a href="#validating-webhook-signatures">Validating Webhook</a> •
24
+ <a href="#testing-and-contributing">Contributing</a>
25
+ </p>
26
+ <sub>This gem is completely inspired by official Coinbase gem <a href="https://github.com/coinbase/coinbase-commerce-ruby">coinbase-commerce-ruby</a>, unfortunately the oficial gem actually is deprecated, and my motivation is to continue support for this gem</sub>
25
27
 
26
28
  ## Ruby Version
27
- Ruby [2.3 -> 3.1.2] are supported and tested.
29
+ Ruby [2.3 -> 3.2.2] are supported and tested.
28
30
 
29
- ## Third Party Libraries and Dependencies
31
+ ## Dependencies
30
32
 
31
33
  The following libraries will be installed when you install the client library:
32
34
  * [faraday](https://github.com/lostisland/faraday)
@@ -38,6 +40,19 @@ For more details visit [Coinbase API docs](https://commerce.coinbase.com/docs/ap
38
40
  To start using library, you'll need to [create a Coinbase Commmerce account](https://commerce.coinbase.com/signup).
39
41
  Once you've created your Coinbase Commerce account, create an ``API_KEY`` in Settings.
40
42
 
43
+ ### On Ruby on Rails
44
+ To use this gem in Ruby on Rails, first pass your Coinbase API_KEY to an environment variable or credentials. After doing this, create a new initializer called `coinbase_commerce_client.rb` and insert the following code:
45
+
46
+ ```ruby
47
+ CoinbaseCommerceClient.configure do |config|
48
+ config.api_key = ENV['COINBASE_API_KEY']
49
+ # or
50
+ config.api_key = Rails.application.credentials.coinbase[:coinbase_api_key]
51
+ end
52
+ ```
53
+
54
+ ### Pure ruby example
55
+
41
56
  Next create a ``Client`` object for interacting with the API:
42
57
  ```ruby
43
58
  require 'coinbase_commerce_client'
@@ -48,21 +63,32 @@ client = CoinbaseCommerceClient::Client.new(api_key: API_KEY)
48
63
  ``Client`` contains links to every Ruby Class representations of the API resources
49
64
  ``Checkout, Charge, Invoices, Event``
50
65
 
51
- You can call ``list, auto_paging, create, retrieve, modify`` methods from API resource classes
66
+ You can call ``list, auto_paging, create, resolve, cancel, retrieve, modify`` methods from API resource classes
52
67
 
53
68
  ```ruby
54
- client.charge.create
55
- client.checkout.auto_paging
56
- client.event.list
57
- client.charge.retrieve
58
- client.checkout.modify
59
- ```
60
- as well as ``save, delete, refresh`` methods from API resource class instances.
61
- ```ruby
69
+ #charges
70
+ client.charge.list
71
+ client.charge.auto_paging
72
+ client.charge.create <payload>
73
+ charge = client.charge.retrieve <id>
74
+ charge.resolve
75
+ charge.cancel
76
+
77
+ #checkout
78
+ client.checkout.list
79
+ client.checkout.auto_paging
80
+ client.checkout.create <payload>
62
81
  checkout = client.checkout.retrieve <id>
63
82
  checkout.refresh
64
83
  checkout.save
84
+ checkout.modify <payload>
65
85
  checkout.delete
86
+
87
+ #events
88
+ client.event.list
89
+ client.event.auto_paging
90
+ event = client.event.retrieve <id>
91
+
66
92
  ```
67
93
 
68
94
  Each API method returns an ``APIObject`` representing the JSON response from the API, all of the models support hash and JSON representation.\
@@ -105,17 +131,25 @@ gem install coinbase_commerce_client
105
131
  ```
106
132
 
107
133
  ## Usage
134
+ * [Checkouts](#checkouts)
135
+ * [Charges](#charges)
136
+ * [Events](#events)
137
+
138
+
108
139
  ```ruby
109
140
  require 'coinbase_commerce_client'
110
141
  client = CoinbaseCommerceClient::Client.new(api_key: 'your_api_key')
111
142
  ```
112
- ## Checkouts
143
+
144
+ ### Checkouts
113
145
  [Checkouts API docs](https://commerce.coinbase.com/docs/api/#checkouts)
114
- ### Retrieve
146
+
147
+ #### Retrieve
115
148
  ```ruby
116
149
  checkout = client.checkout.retrieve <checkout_id>
117
150
  ```
118
- ### Create
151
+
152
+ #### Create
119
153
  ```ruby
120
154
  checkout_info = {
121
155
  "name": "The Sovereign Individual",
@@ -139,7 +173,7 @@ checkout = client.checkout.create(:name=>'The Sovereign Individual',
139
173
  :requested_info=>["name", "email"])
140
174
  ```
141
175
 
142
- ### Update
176
+ #### Update
143
177
  ```ruby
144
178
  checkout = client.checkout.retrieve <checkout_id>
145
179
  checkout.name = 'new name'
@@ -151,28 +185,32 @@ client.checkout.modify(<checkout_id>, "local_price": {
151
185
  })
152
186
  ```
153
187
 
154
- ### Delete
188
+ #### Delete
155
189
  ```ruby
156
190
  checkout.delete
157
191
  ```
158
- ### List
192
+
193
+ #### List
159
194
  ```ruby
160
195
  checkouts = client.checkout.list
161
196
  ```
162
- ### Paging list iterations
197
+
198
+ #### Paging list iterations
163
199
  ```ruby
164
200
  client.checkout.auto_paging do |ch|
165
201
  puts ch.id
166
202
  end
167
203
  ```
168
204
 
169
- ## Charges
170
- [Charges API docs](https://commerce.coinbase.com/docs/api/#charges)
171
- ### Retrieve
205
+ ### Charges
206
+ [Charges API docs](https://docs.cloud.coinbase.com/commerce/reference/getcharges)
207
+
208
+ #### Retrieve
172
209
  ```ruby
173
210
  charge = client.charge.retrieve <charge_id>
174
211
  ```
175
- ### Create
212
+
213
+ #### Create
176
214
  ```ruby
177
215
  charge_info = {
178
216
  "name": "The Sovereign Individual",
@@ -194,34 +232,45 @@ charge = client.charge.create(:name=>'The Sovereign Individual',
194
232
  "currency": "USD"
195
233
  })
196
234
  ```
197
- ### List
235
+
236
+ #### List
198
237
  ```ruby
199
238
  charges_list = client.charge.list
200
239
  ```
201
- ### Cancel
202
- ```ruby
203
- charge = client.charge.retrieve <charge_id>
204
-
205
- charge.cancel
206
- ```
207
- ### Paging list iterations
240
+
241
+ #### Paging list iterations
208
242
  ```ruby
209
243
  client.charge.auto_paging do |charge|
210
244
  puts charge.id
211
245
  end
212
246
  ```
213
247
 
248
+ #### Resolve
249
+ ```ruby
250
+ charge = client.charge.retrieve <charge_id>
251
+ charge.resolve
252
+ ```
253
+
254
+ #### Cancel
255
+ ```ruby
256
+ charge = client.charge.retrieve <charge_id>
257
+ charge.cancel
258
+ ```
259
+
214
260
  ## Events
215
- [Events API Docs](https://commerce.coinbase.com/docs/api/#events)
216
- ### Retrieve
261
+ [Events API Docs](https://docs.cloud.coinbase.com/commerce/reference/getevents)
262
+
263
+ #### Retrieve
217
264
  ```ruby
218
265
  event = client.event.retrieve <event_id>
219
266
  ```
220
- ### List
267
+
268
+ #### List
221
269
  ```ruby
222
270
  events = client.event.list
223
271
  ```
224
- ### Paging list iterations
272
+
273
+ #### Paging list iterations
225
274
  ```ruby
226
275
  client.event.auto_paging do |event|
227
276
  puts event.id
@@ -244,7 +293,7 @@ post '/webhooks' do
244
293
  # event handle
245
294
  puts "Received event id=#{event.id}, type=#{event.type}"
246
295
  status 200
247
- # errors handle
296
+ # errors handle
248
297
  rescue JSON::ParserError => e
249
298
  puts "json parse error"
250
299
  status 400
data/badge.svg CHANGED
@@ -1 +1 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="114" height="20" role="img" aria-label="coverage: 89.18%"><title>coverage: 89.18%</title><linearGradient id="s" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="r"><rect width="114" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#r)"><rect width="61" height="20" fill="#555"/><rect x="61" width="53" height="20" fill="#97ca00"/><rect width="114" height="20" fill="url(#s)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="315" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="510">coverage</text><text x="315" y="140" transform="scale(.1)" fill="#fff" textLength="510">coverage</text><text aria-hidden="true" x="865" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="430">89.18%</text><text x="865" y="140" transform="scale(.1)" fill="#fff" textLength="430">89.18%</text></g></svg>
1
+ <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="114" height="20" role="img" aria-label="coverage: 89.66%"><title>coverage: 89.66%</title><linearGradient id="s" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="r"><rect width="114" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#r)"><rect width="61" height="20" fill="#555"/><rect x="61" width="53" height="20" fill="#97ca00"/><rect width="114" height="20" fill="url(#s)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="315" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="510">coverage</text><text x="315" y="140" transform="scale(.1)" fill="#fff" textLength="510">coverage</text><text aria-hidden="true" x="865" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="430">89.66%</text><text x="865" y="140" transform="scale(.1)" fill="#fff" textLength="430">89.66%</text></g></svg>
@@ -0,0 +1,13 @@
1
+ module CoinbaseCommerceClient
2
+ module APIResources
3
+ module Base
4
+ module Resolve
5
+ def resolve
6
+ resp = @client.request(:post, "#{self.class::RESOURCE_PATH}/#{self[:id]}/resolve", self)
7
+ initialize_from(resp.data)
8
+ self
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -5,6 +5,7 @@ module CoinbaseCommerceClient
5
5
  extend Base::Create
6
6
 
7
7
  include Base::Cancel
8
+ include Base::Resolve
8
9
 
9
10
  OBJECT_NAME = 'charge'.freeze
10
11
  RESOURCE_PATH = 'charges'.freeze
@@ -2,10 +2,28 @@ module CoinbaseCommerceClient
2
2
  BASE_API_URL = 'https://api.commerce.coinbase.com/'.freeze
3
3
  API_VERSION = '2018-03-22'.freeze
4
4
 
5
+ class Configuration
6
+ attr_accessor :api_key
7
+
8
+ def initialize
9
+ @api_key = nil
10
+ end
11
+ end
12
+
13
+ @configuration = Configuration.new
14
+
15
+ def self.configure
16
+ yield(@configuration)
17
+ end
18
+
19
+ def self.config
20
+ @configuration
21
+ end
22
+
5
23
  class Client
6
24
  def initialize(options = {})
7
25
  check_api_key!(options[:api_key])
8
- @api_key = options[:api_key]
26
+ @api_key = options[:api_key] || CoinbaseCommerceClient.config.api_key
9
27
  @api_uri = URI.parse(options[:api_url] || BASE_API_URL)
10
28
  @api_ver = options[:api_ver] || API_VERSION
11
29
 
@@ -46,7 +64,7 @@ module CoinbaseCommerceClient
46
64
  end
47
65
 
48
66
  def check_api_key!(api_key)
49
- raise AuthenticationError, 'No API key provided' unless api_key
67
+ raise CoinbaseCommerceClient::Errors::AuthenticationError, 'No API key provided' unless (api_key || CoinbaseCommerceClient.config.api_key)
50
68
  end
51
69
 
52
70
  def request(method, path, params = {})
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CoinbaseCommerceClient
4
- VERSION = '0.2.0'
4
+ VERSION = '0.4.2'
5
5
  end
@@ -26,6 +26,7 @@ require "coinbase_commerce_client/api_resources/base/api_resource"
26
26
  require "coinbase_commerce_client/api_resources/base/create"
27
27
  require "coinbase_commerce_client/api_resources/base/update"
28
28
  require "coinbase_commerce_client/api_resources/base/cancel"
29
+ require "coinbase_commerce_client/api_resources/base/resolve"
29
30
  require "coinbase_commerce_client/api_resources/base/save"
30
31
  require "coinbase_commerce_client/api_resources/base/list"
31
32
  require "coinbase_commerce_client/api_resources/base/delete"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coinbase_commerce_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vinicius Borges
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-10-15 00:00:00.000000000 Z
11
+ date: 2024-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -111,6 +111,7 @@ files:
111
111
  - lib/coinbase_commerce_client/api_resources/base/create.rb
112
112
  - lib/coinbase_commerce_client/api_resources/base/delete.rb
113
113
  - lib/coinbase_commerce_client/api_resources/base/list.rb
114
+ - lib/coinbase_commerce_client/api_resources/base/resolve.rb
114
115
  - lib/coinbase_commerce_client/api_resources/base/save.rb
115
116
  - lib/coinbase_commerce_client/api_resources/base/update.rb
116
117
  - lib/coinbase_commerce_client/api_resources/charge.rb
@@ -122,14 +123,14 @@ files:
122
123
  - lib/coinbase_commerce_client/version.rb
123
124
  - lib/coinbase_commerce_client/webhooks.rb
124
125
  - sig/coinbase_commerce_client.rbs
125
- homepage: https://github.com/viniciusborgeis/coinbase_commerce_client
126
+ homepage: https://github.com/BiteCraft/coinbase_commerce_client
126
127
  licenses:
127
128
  - MIT
128
129
  metadata:
129
- homepage_uri: https://github.com/viniciusborgeis/coinbase_commerce_client
130
- source_code_uri: https://github.com/viniciusborgeis/coinbase_commerce_client
131
- changelog_uri: https://github.com/viniciusborgeis/coinbase_commerce_client
132
- post_install_message:
130
+ homepage_uri: https://github.com/BiteCraft/coinbase_commerce_client
131
+ source_code_uri: https://github.com/BiteCraft/coinbase_commerce_client
132
+ changelog_uri: https://github.com/BiteCraft/coinbase_commerce_client
133
+ post_install_message:
133
134
  rdoc_options: []
134
135
  require_paths:
135
136
  - lib
@@ -144,8 +145,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
145
  - !ruby/object:Gem::Version
145
146
  version: '0'
146
147
  requirements: []
147
- rubygems_version: 3.3.7
148
- signing_key:
148
+ rubygems_version: 3.2.3
149
+ signing_key:
149
150
  specification_version: 4
150
151
  summary: Coinbase Commerce integration client for crypto payments
151
152
  test_files: []