omise 0.7.1 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/ruby.yml +27 -0
  3. data/.gitignore +1 -0
  4. data/CHANGELOG.md +27 -1
  5. data/LICENSE.txt +1 -1
  6. data/README.md +27 -45
  7. data/lib/omise/account.rb +12 -1
  8. data/lib/omise/all.rb +4 -0
  9. data/lib/omise/capability.rb +32 -0
  10. data/lib/omise/charge.rb +8 -0
  11. data/lib/omise/config.rb +5 -1
  12. data/lib/omise/dispute.rb +4 -0
  13. data/lib/omise/integration.rb +16 -0
  14. data/lib/omise/link.rb +4 -0
  15. data/lib/omise/receipt.rb +20 -0
  16. data/lib/omise/resource.rb +0 -2
  17. data/lib/omise/schedule.rb +4 -0
  18. data/lib/omise/scheduler.rb +1 -1
  19. data/lib/omise/source.rb +15 -0
  20. data/lib/omise/version.rb +1 -1
  21. data/test/fixtures/api.omise.co/account-get.json +2 -0
  22. data/test/fixtures/api.omise.co/account-patch.json +8 -0
  23. data/test/fixtures/api.omise.co/capability-get.json +29 -0
  24. data/test/fixtures/api.omise.co/charges/chrg_test_4yq7duw15p9hdrjp8oq/events-get.json +28 -0
  25. data/test/fixtures/api.omise.co/charges/chrg_test_4yq7duw15p9hdrjp8oq/expire-post.json +51 -0
  26. data/test/fixtures/api.omise.co/disputes/dspt_test_5089off452g5m5te7xs/accept-patch.json +12 -0
  27. data/test/fixtures/api.omise.co/integrations/integration_test_5h24qlv37qyx537p1ub-get.json +12 -0
  28. data/test/fixtures/api.omise.co/links/link_test_55pcclmznvrv9lc7r9s-delete.json +6 -0
  29. data/test/fixtures/api.omise.co/receipts-get.json +90 -0
  30. data/test/fixtures/api.omise.co/receipts/rcpt_5ls0b8zb53qmw3mlvfz-get.json +39 -0
  31. data/test/fixtures/api.omise.co/schedules/schd_test_4yq7duw15p9hdrjp8oq-delete.json +1 -1
  32. data/test/fixtures/api.omise.co/schedules/schd_test_4yq7duw15p9hdrjp8oq-get.json +1 -0
  33. data/test/fixtures/api.omise.co/sources-post.json +6 -0
  34. data/test/fixtures/api.omise.co/sources/src_test_59trf2nxk43b5nml8z0-get.json +8 -0
  35. data/test/omise/test_account.rb +7 -1
  36. data/test/omise/test_capability.rb +30 -0
  37. data/test/omise/test_charge.rb +11 -0
  38. data/test/omise/test_dispute.rb +18 -0
  39. data/test/omise/test_integration.rb +12 -0
  40. data/test/omise/test_link.rb +7 -0
  41. data/test/omise/test_receipt.rb +29 -0
  42. data/test/omise/test_schedule.rb +8 -0
  43. data/test/omise/test_scheduler.rb +13 -0
  44. data/test/omise/test_source.rb +20 -0
  45. data/test/support.rb +1 -0
  46. metadata +42 -10
  47. data/circle.yml +0 -3
  48. data/data/ca_certificates.pem +0 -162
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: bc3ed7874767ee929bd07b3579faec6fdbaf3a22
4
- data.tar.gz: ac029be84b38f795b6f163f1fa9a6dba1dd757c5
2
+ SHA256:
3
+ metadata.gz: 0ba27e7fa52e39678ea8eeea60526fd163e071cdf2fb45177476ba023fc7c64c
4
+ data.tar.gz: 7e7f22f38b1a716034c27d9f8ded31b3b8a7e97e83056a07d8aef3909819d128
5
5
  SHA512:
6
- metadata.gz: 4378039e687cc23acb12b3afe3c7d8dfe016c14bf3848c717c8d85d1b9bac1e02867d57a7eefbeb4aac162f003a45f903136fbef6a2664b24eb1a827365d1c2e
7
- data.tar.gz: 155b4409ba41338eed7dadd9988c1eb666ee3450c9e481071d028d659726a25472be0a550d301f4b47a0e0b63a205b4be4d25fa7f8f86be64a4ec2ec827f1ddc
6
+ metadata.gz: 738cafc6e546810c4ae8b3de8e2ea788a39de04c5eb4048b9cc90aa72e53cfac1177190c453af097a2e17824e7cf22acca9d0eafb093e5bed12c27554fc0eb74
7
+ data.tar.gz: 6ec041635455df84aa2063c462c41a5abb4ff23b56565214fb7e84e12702473a1ff4e1372e12feca376078d4a049cdb8bb4973e06494bc00ad7a18c677f55dcc
@@ -0,0 +1,27 @@
1
+ name: Ruby
2
+
3
+ on:
4
+ push:
5
+ branches: [ 'master' ]
6
+ pull_request:
7
+ branches: [ 'master' ]
8
+
9
+ jobs:
10
+ build:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ ruby: [ '2.5', '2.6', '2.7', '3.0' ]
15
+ name: Ruby ${{ matrix.ruby }}
16
+ steps:
17
+ - uses: actions/checkout@v2
18
+ - name: Setup ruby
19
+ uses: actions/setup-ruby@v1
20
+ with:
21
+ ruby-version: ${{ matrix.ruby }}
22
+
23
+ - name: Build and test with Rake
24
+ run: |
25
+ gem install bundler
26
+ bundle install --jobs 4 --retry 3
27
+ bundle exec rake test
data/.gitignore CHANGED
@@ -12,3 +12,4 @@
12
12
  *.o
13
13
  *.a
14
14
  mkmf.log
15
+ .DS_Store
data/CHANGELOG.md CHANGED
@@ -2,6 +2,32 @@
2
2
 
3
3
  An [unreleased] version is not available on rubygems and is subject to changes and must not be considered final. Elements of unreleased list may be edited or removed at any time.
4
4
 
5
+ ## [0.10.0] 2021-02-16
6
+
7
+ - [Added] Add a new method to fetch all events belonging to a charge (https://github.com/omise/omise-ruby/pull/45)
8
+ - [Added] Add Receipt API (https://github.com/omise/omise-ruby/pull/44)
9
+ - [Added] Allow shortened form of ordinal numbers on Scheduler (https://github.com/omise/omise-ruby/pull/43)
10
+ - [Added] Add update method for Account (https://github.com/omise/omise-ruby/pull/42)
11
+ - [Added] Add accept method for Dispute (https://github.com/omise/omise-ruby/pull/41)
12
+ - [Added] Add expire method for Charge (https://github.com/omise/omise-ruby/pull/40)
13
+ - [Added] Add destroy method for Link (https://github.com/omise/omise-ruby/pull/39)
14
+
15
+ ## [0.9.1] 2019-11-15
16
+
17
+ - [Fixed] Tests
18
+
19
+ ## [0.9.0] 2019-11-15
20
+
21
+ - [Added] Integrations support
22
+
23
+ ## [0.8.0] 2019-11-04
24
+
25
+ - [Added] Capability object
26
+
27
+ ## [0.7.2] 2019-09-30
28
+
29
+ - [Changed] Removed CA certificate pining
30
+
5
31
  ## [0.7.1] 2017-12-13
6
32
 
7
33
  - [Added] Ability to add a suffix to the user agent
@@ -65,7 +91,7 @@ An [unreleased] version is not available on rubygems and is subject to changes a
65
91
  ## [0.1.0] 2015-01-19
66
92
 
67
93
  - [Added] Add support for the Refund API.
68
- - [Added] Add a test suite that can be run locally without the need for a
94
+ - [Added] Add a test suite that can be run locally without the need for a
69
95
  network connection or to set Omise keys.
70
96
  - [Added] Add a list method to retrieve a list of objects.
71
97
  - [Changed] Move typecast and load_response methods into a Util module.
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014 Omise
1
+ Copyright (c) 2019 Omise
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -1,19 +1,18 @@
1
1
  # Omise Ruby Client
2
2
 
3
- [![CodeClimate](https://img.shields.io/codeclimate/github/omise/omise-ruby.svg?style=flat)](https://codeclimate.com/github/omise/omise-ruby)
4
- ![CircleCI](https://img.shields.io/circleci/project/omise/omise-ruby.svg?style=flat)
3
+ [![Maintainability](https://api.codeclimate.com/v1/badges/8297834e28572da75cf2/maintainability)](https://codeclimate.com/github/omise/omise-ruby/maintainability)
4
+ <img alt="GitHub Actions status" src="https://github.com/omise/omise-ruby/workflows/Ruby/badge.svg">
5
5
  [![Gem](https://img.shields.io/gem/v/omise.svg?style=flat)](https://rubygems.org/gems/omise)
6
- [![Join the chat at https://gitter.im/omise/omise-ruby](https://badges.gitter.im/omise/omise-ruby.svg)](https://gitter.im/omise/omise-ruby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
7
6
 
8
7
  ## Installation
9
8
 
10
- Installing via rubygems:
9
+ Add the following to your `Gemfile` and run `bundle install` to install via [RubyGems](https://rubygems.org/gems/omise):
11
10
 
12
11
  ```ruby
13
12
  gem 'omise'
14
13
  ```
15
14
 
16
- Or use the cutting-edge version by installing via github:
15
+ Or use the cutting-edge version by installing via GitHub:
17
16
 
18
17
  ```ruby
19
18
  gem 'omise', github: 'omise/omise-ruby'
@@ -21,28 +20,38 @@ gem 'omise', github: 'omise/omise-ruby'
21
20
 
22
21
  ## Requirements
23
22
 
24
- Requires ruby 1.9.2 or above, the rest-client and json gems.
23
+ Tested on Ruby 2.5 and above
25
24
 
26
25
  ## Configuration
27
26
 
28
27
  First configure your secret key:
29
28
 
30
29
  ```ruby
30
+ require "omise"
31
+
31
32
  Omise.api_key = "skey_test_xxxxxxxxxxxxxxxxxxx"
32
33
  ```
33
34
 
34
- If you need to use the Token API you also need to set your public key:
35
+ After you have implemented [Omise.js](https://www.omise.co/omise-js) on your frontend you can charge the card by passing the token generated by Omise.js into the `card` attribute.
35
36
 
36
37
  ```ruby
37
- Omise.public_api_key = "pkey_test_xxxxxxxxxxxxxxxxxxx"
38
- ```
38
+ # Charge 1000.00 THB
39
+ charge = Omise::Charge.create({
40
+ amount: 1_000_00,
41
+ currency: "thb",
42
+ card: params[:omise_token]
43
+ })
39
44
 
40
- With this set you'll be able to retrieve tokens or create new ones.
45
+ if charge.paid
46
+ # handle success
47
+ puts "thanks"
48
+ else
49
+ # handle failure
50
+ raise charge.failure_code
51
+ end
52
+ ```
41
53
 
42
- However we recommend using [Omise.js](https://www.omise.co/omise-js-api) to
43
- [collect cards](https://www.omise.co/collecting-card-information). When creating a token server side you'll need card data
44
- transiting to and from your server and this requires that your organization be
45
- PCI compliant.
54
+ You can check the complete documentation at [omise.co/docs](https://omise.co/docs).
46
55
 
47
56
  ### API version
48
57
 
@@ -53,18 +62,16 @@ environments with different API versions (e.g. development on the latest but
53
62
  production on the older version).
54
63
 
55
64
  ```ruby
56
- require "omise"
57
- Omise.api_version = "2014-07-27"
65
+ Omise.api_version = "2019-05-29"
58
66
  ```
59
67
 
60
- It is highly recommended to set this version to the current version
61
- you're using.
68
+ It is highly recommended to set this version to the current version you're using.
62
69
 
63
70
  ### Logging
64
71
 
65
- To enable log you can set `Omise.logger` with a Ruby logger. All HTTP requests and responses will be logged.
72
+ To enable logging you can set `Omise.logger` with a Ruby logger. All HTTP requests and responses will be logged.
66
73
 
67
- To disable log, just configure `Omise.logger` to `nil`. Default is disabled.
74
+ To disable logging, just configure `Omise.logger` to `nil`. Default is disabled.
68
75
 
69
76
  An example configuring Rails logger:
70
77
 
@@ -72,31 +79,6 @@ An example configuring Rails logger:
72
79
  Omise.logger = Rails.logger
73
80
  ```
74
81
 
75
- ## Quick Start
76
-
77
- After you have implemented [Omise.js](https://www.omise.co/omise-js-api) on your
78
- frontend you can charge the card by passing the token into the `card` attribute.
79
-
80
- ```ruby
81
- # Charge 1000.00 THB
82
- charge = Omise::Charge.create({
83
- amount: 1_000_00,
84
- currency: "thb",
85
- card: params[:omise_token]
86
- })
87
-
88
- if charge.paid
89
- # handle success
90
- puts "thanks"
91
- else
92
- # handle failure
93
- raise charge.failure_code
94
- end
95
- ```
96
-
97
- You can check the complete documentation at
98
- [omise.co/docs](https://omise.co/docs).
99
-
100
82
  ## Development
101
83
 
102
84
  The test suite can be run with `bundle exec rake test`.
data/lib/omise/account.rb CHANGED
@@ -3,6 +3,17 @@ require "omise/object"
3
3
  module Omise
4
4
  class Account < OmiseObject
5
5
  self.endpoint = "/account"
6
- singleton!
6
+
7
+ def self.retrieve(attributes = {})
8
+ new resource(location, attributes).get(attributes)
9
+ end
10
+
11
+ def reload(attributes = {})
12
+ assign_attributes resource(attributes).get(attributes)
13
+ end
14
+
15
+ def update(attributes = {})
16
+ assign_attributes resource(attributes).patch(attributes)
17
+ end
7
18
  end
8
19
  end
data/lib/omise/all.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "omise/account"
2
2
  require "omise/balance"
3
3
  require "omise/bank_account"
4
+ require "omise/capability"
4
5
  require "omise/card"
5
6
  require "omise/chain"
6
7
  require "omise/charge"
@@ -9,11 +10,14 @@ require "omise/dispute"
9
10
  require "omise/document"
10
11
  require "omise/event"
11
12
  require "omise/forex"
13
+ require "omise/integration"
12
14
  require "omise/link"
13
15
  require "omise/occurrence"
16
+ require "omise/receipt"
14
17
  require "omise/recipient"
15
18
  require "omise/refund"
16
19
  require "omise/search"
20
+ require "omise/source"
17
21
  require "omise/schedule"
18
22
  require "omise/token"
19
23
  require "omise/transaction"
@@ -0,0 +1,32 @@
1
+ require "omise/object"
2
+
3
+ module Omise
4
+ class Capability < OmiseObject
5
+ self.endpoint = "/capability"
6
+ singleton!
7
+
8
+ PaymentMethod = Struct.new(
9
+ :object,
10
+ :name,
11
+ :currencies,
12
+ :card_brands,
13
+ :installment_terms
14
+ )
15
+
16
+ def self.resource_key
17
+ Omise.public_api_key
18
+ end
19
+
20
+ def payment_methods
21
+ self["payment_methods"].map do |payment_method|
22
+ PaymentMethod.new(
23
+ payment_method["object"],
24
+ payment_method["name"],
25
+ payment_method["currencies"],
26
+ payment_method["card_brands"],
27
+ payment_method["installment_terms"]
28
+ )
29
+ end
30
+ end
31
+ end
32
+ end
data/lib/omise/charge.rb CHANGED
@@ -44,6 +44,10 @@ module Omise
44
44
  assign_attributes nested_resource("reverse", options).post
45
45
  end
46
46
 
47
+ def expire(options = {})
48
+ assign_attributes nested_resource("expire", options).post
49
+ end
50
+
47
51
  def customer(options = {})
48
52
  if !defined?(Customer)
49
53
  require "omise/customer"
@@ -68,6 +72,10 @@ module Omise
68
72
  expand_attribute Transaction, "transaction", options
69
73
  end
70
74
 
75
+ def events(attributes = {})
76
+ List.new nested_resource("events", attributes).get(attributes)
77
+ end
78
+
71
79
  def refunds
72
80
  list_attribute RefundList, "refunds"
73
81
  end
data/lib/omise/config.rb CHANGED
@@ -7,7 +7,7 @@ module Omise
7
7
  class << self
8
8
  attr_accessor :api_url, :vault_url, :api_version, :resource, :user_agent_suffix
9
9
 
10
- attr_writer :secret_api_key, :public_api_key
10
+ attr_writer :secret_api_key, :public_api_key, :app_key
11
11
 
12
12
  def secret_api_key
13
13
  get_key :secret_api_key
@@ -17,6 +17,10 @@ module Omise
17
17
  get_key :public_api_key
18
18
  end
19
19
 
20
+ def app_key
21
+ get_key :app_key
22
+ end
23
+
20
24
  # Backward compatibility with old API Keys naming conventions
21
25
  #
22
26
  # Will be removed in 1.0
data/lib/omise/dispute.rb CHANGED
@@ -28,6 +28,10 @@ module Omise
28
28
  assign_attributes resource(attributes).patch(attributes)
29
29
  end
30
30
 
31
+ def accept(attributes = {})
32
+ assign_attributes nested_resource("accept", attributes).patch(attributes)
33
+ end
34
+
31
35
  def charge(options = {})
32
36
  if !defined?(Charge)
33
37
  require "omise/charge"
@@ -0,0 +1,16 @@
1
+ require "omise/object"
2
+
3
+ module Omise
4
+ class Integration < OmiseObject
5
+ self.endpoint = "/integrations"
6
+
7
+ def self.retrieve(id, attributes = {})
8
+ new resource(location(id), attributes).get(attributes)
9
+ end
10
+
11
+ def self.resource_key
12
+ Omise.app_key
13
+ end
14
+
15
+ end
16
+ end
data/lib/omise/link.rb CHANGED
@@ -27,6 +27,10 @@ module Omise
27
27
  assign_attributes resource(attributes).get(attributes)
28
28
  end
29
29
 
30
+ def destroy(attributes = {})
31
+ assign_attributes resource(attributes).delete
32
+ end
33
+
30
34
  def charges(options = {})
31
35
  if options.empty?
32
36
  list_attribute ChargeList, "charges"
@@ -0,0 +1,20 @@
1
+ require "omise/object"
2
+ require "omise/list"
3
+
4
+ module Omise
5
+ class Receipt < OmiseObject
6
+ self.endpoint = "/receipts"
7
+
8
+ def self.retrieve(id, attributes = {})
9
+ new resource(location(id), attributes).get(attributes)
10
+ end
11
+
12
+ def self.list(attributes = {})
13
+ List.new resource(location, attributes).get(attributes)
14
+ end
15
+
16
+ def reload(attributes = {})
17
+ assign_attributes resource(attributes).get(attributes)
18
+ end
19
+ end
20
+ end
@@ -7,7 +7,6 @@ require "omise/version"
7
7
 
8
8
  module Omise
9
9
  class Resource
10
- CA_BUNDLE_PATH = File.expand_path("../../../data/ca_certificates.pem", __FILE__)
11
10
  DEFAULT_HEADERS = {
12
11
  user_agent: "OmiseRuby/#{Omise::VERSION} Ruby/#{RUBY_VERSION}",
13
12
  }
@@ -61,7 +60,6 @@ module Omise
61
60
  @resource = RestClient::Resource.new(@uri.to_s, {
62
61
  user: @key,
63
62
  verify_ssl: OpenSSL::SSL::VERIFY_PEER,
64
- ssl_ca_file: CA_BUNDLE_PATH,
65
63
  headers: @headers,
66
64
  })
67
65
  end
@@ -25,5 +25,9 @@ module Omise
25
25
  def destroy(attributes = {})
26
26
  assign_attributes resource(attributes).delete
27
27
  end
28
+
29
+ def destroyed?
30
+ status == "deleted"
31
+ end
28
32
  end
29
33
  end
@@ -5,7 +5,7 @@ require "omise/schedule"
5
5
  module Omise
6
6
  class Scheduler
7
7
  WEEKDAYS = Date::DAYNAMES.map(&:downcase).freeze
8
- MONTH_WEEKDAYS = %w[first second third fourth last]
8
+ MONTH_WEEKDAYS = %w[first 1st second 2nd third 3rd fourth 4th last]
9
9
  .product(WEEKDAYS)
10
10
  .map { |d| d.join("_") }
11
11
  .freeze