omise 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +14 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +56 -0
  6. data/Rakefile +8 -0
  7. data/data/ca_certificates.pem +105 -0
  8. data/lib/omise.rb +6 -0
  9. data/lib/omise/account.rb +8 -0
  10. data/lib/omise/all.rb +9 -0
  11. data/lib/omise/attributes.rb +63 -0
  12. data/lib/omise/balance.rb +8 -0
  13. data/lib/omise/card.rb +19 -0
  14. data/lib/omise/card_list.rb +22 -0
  15. data/lib/omise/charge.rb +55 -0
  16. data/lib/omise/config.rb +36 -0
  17. data/lib/omise/customer.rb +50 -0
  18. data/lib/omise/error.rb +12 -0
  19. data/lib/omise/list.rb +37 -0
  20. data/lib/omise/object.rb +60 -0
  21. data/lib/omise/refund.rb +32 -0
  22. data/lib/omise/refund_list.rb +19 -0
  23. data/lib/omise/resource.rb +43 -0
  24. data/lib/omise/singleton_resource.rb +21 -0
  25. data/lib/omise/testing/resource.rb +38 -0
  26. data/lib/omise/token.rb +26 -0
  27. data/lib/omise/transaction.rb +16 -0
  28. data/lib/omise/transfer.rb +32 -0
  29. data/lib/omise/util.rb +24 -0
  30. data/lib/omise/vault.rb +15 -0
  31. data/lib/omise/version.rb +3 -0
  32. data/omise.gemspec +25 -0
  33. data/test/fixtures/api.omise.co/account-get.json +6 -0
  34. data/test/fixtures/api.omise.co/balance-get.json +7 -0
  35. data/test/fixtures/api.omise.co/charges-get.json +59 -0
  36. data/test/fixtures/api.omise.co/charges-post.json +36 -0
  37. data/test/fixtures/api.omise.co/charges/404-get.json +6 -0
  38. data/test/fixtures/api.omise.co/charges/chrg_test_4yq7duw15p9hdrjp8oq-get.json +58 -0
  39. data/test/fixtures/api.omise.co/charges/chrg_test_4yq7duw15p9hdrjp8oq-patch.json +58 -0
  40. data/test/fixtures/api.omise.co/charges/chrg_test_4yq7duw15p9hdrjp8oq/refunds-get.json +21 -0
  41. data/test/fixtures/api.omise.co/charges/chrg_test_4yq7duw15p9hdrjp8oq/refunds-post.json +10 -0
  42. data/test/fixtures/api.omise.co/charges/chrg_test_4yq7duw15p9hdrjp8oq/refunds/404-get.json +6 -0
  43. data/test/fixtures/api.omise.co/charges/chrg_test_4yq7duw15p9hdrjp8oq/refunds/rfnd_test_4yqmv79ahghsiz23y3c-get.json +10 -0
  44. data/test/fixtures/api.omise.co/customers-get.json +49 -0
  45. data/test/fixtures/api.omise.co/customers-post.json +22 -0
  46. data/test/fixtures/api.omise.co/customers/404-get.json +6 -0
  47. data/test/fixtures/api.omise.co/customers/cust_test_4yq6txdpfadhbaqnwp3-delete.json +6 -0
  48. data/test/fixtures/api.omise.co/customers/cust_test_4yq6txdpfadhbaqnwp3-get.json +39 -0
  49. data/test/fixtures/api.omise.co/customers/cust_test_4yq6txdpfadhbaqnwp3-patch.json +39 -0
  50. data/test/fixtures/api.omise.co/customers/cust_test_4yq6txdpfadhbaqnwp3/cards/404-get.json +6 -0
  51. data/test/fixtures/api.omise.co/customers/cust_test_4yq6txdpfadhbaqnwp3/cards/card_test_4yq6tuucl9h4erukfl0-delete.json +6 -0
  52. data/test/fixtures/api.omise.co/customers/cust_test_4yq6txdpfadhbaqnwp3/cards/card_test_4yq6tuucl9h4erukfl0-get.json +18 -0
  53. data/test/fixtures/api.omise.co/customers/cust_test_4yq6txdpfadhbaqnwp3/cards/card_test_4yq6tuucl9h4erukfl0-patch.json +18 -0
  54. data/test/fixtures/api.omise.co/transactions-get.json +26 -0
  55. data/test/fixtures/api.omise.co/transactions/trxn_test_4yq7duwb9jts1vxgqua-get.json +8 -0
  56. data/test/fixtures/api.omise.co/transactions/trxn_test_4yqafnvlztbf3908vs1-get.json +8 -0
  57. data/test/fixtures/api.omise.co/transactions/trxn_test_4yqmv79fzpy0gmz5mmq-get.json +8 -0
  58. data/test/fixtures/api.omise.co/transfers-get.json +24 -0
  59. data/test/fixtures/api.omise.co/transfers-post.json +14 -0
  60. data/test/fixtures/api.omise.co/transfers/trsf_test_4yqacz8t3cbipcj766u-get.json +14 -0
  61. data/test/fixtures/vault.omise.co/tokens-post.json +25 -0
  62. data/test/fixtures/vault.omise.co/tokens/tokn_test_4yq8lbecl0q6dsjzxr5-get.json +25 -0
  63. data/test/omise/test_account.rb +19 -0
  64. data/test/omise/test_balance.rb +19 -0
  65. data/test/omise/test_card.rb +52 -0
  66. data/test/omise/test_charge.rb +56 -0
  67. data/test/omise/test_customer.rb +59 -0
  68. data/test/omise/test_refund.rb +41 -0
  69. data/test/omise/test_token.rb +31 -0
  70. data/test/omise/test_transaction.rb +18 -0
  71. data/test/omise/test_transfer.rb +24 -0
  72. data/test/support.rb +12 -0
  73. data/test/test_omise.rb +7 -0
  74. metadata +214 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a62637552d01df079f85217d27317fa50b720459
4
+ data.tar.gz: 0546a78676c1d55fc0e0cc75fce39647cce135ba
5
+ SHA512:
6
+ metadata.gz: 35c950bc2ea666234ab9fed87a8fe0c88f05f68d2845b0d43bc41aea7abf3288e8aa8e2cb7826d693d177992e19ebd0bc13afe31f39653b436cf5a9fa5e048d7
7
+ data.tar.gz: 02e246bebf9575c8369f46c6aa891809b455f3658d0481e0673bb1fd80284fec3c4f30e72ac72a873a91ad0d5e696e8a93f3f33677165120e4f8b61295e24769
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in omise.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Omise
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,56 @@
1
+ # Omise Ruby Client
2
+
3
+ [![Code Climate](https://codeclimate.com/github/omise/omise-ruby/badges/gpa.svg)](https://codeclimate.com/github/omise/omise-ruby)
4
+
5
+ ## Installation
6
+
7
+ Install using bundle (via github only at this time).
8
+
9
+ ```ruby
10
+ gem 'omise', github: 'omise/omise-ruby'
11
+ ```
12
+
13
+ ## Examples
14
+
15
+ First configure your api key.
16
+
17
+ ```ruby
18
+ Omise.api_key = "skey_test_4xa89ox4z4bcfrikkh2"
19
+ ```
20
+
21
+ Then you're ready to go. Here's how to create customer:
22
+
23
+ ```ruby
24
+ customer = Omise::Customer.create({
25
+ description: "John Doe",
26
+ email: "john.doe@example.com"
27
+ })
28
+
29
+ puts customer.attributes
30
+ # {
31
+ # "object" => "customer",
32
+ # "id" => "...",
33
+ # "livemode" => false,
34
+ # "location" => "/customers/...",
35
+ # "default_card" => nil,
36
+ # "email" => "john.doe@example.com",
37
+ # "description" => "John Doe",
38
+ # "created" => "2014-09-05T09:03:05Z",
39
+ # "cards" => {
40
+ # "object": "list",
41
+ # ...
42
+ # }
43
+ # }
44
+ ```
45
+
46
+ Then find, update and destroy that customer.
47
+
48
+ ```ruby
49
+ customer = Omise::Customer.find("cust_test_4xald9y2ttb5mvplw0c")
50
+
51
+ customer.update description: "John W. Doe"
52
+ customer.description # => "John W. Doe"
53
+
54
+ customer.destroy
55
+ customer.destroyed? # => true
56
+ ```
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << "./lib"
6
+ t.libs << "./test"
7
+ t.test_files = FileList["test/**/test_*.rb"]
8
+ end
@@ -0,0 +1,105 @@
1
+ Country: US
2
+ Organization: Equifax
3
+ Common Name: Equifax Secure CA
4
+ -----BEGIN CERTIFICATE-----
5
+ MIIDIDCCAomgAwIBAgIENd70zzANBgkqhkiG9w0BAQUFADBOMQswCQYDVQQGEwJV
6
+ UzEQMA4GA1UEChMHRXF1aWZheDEtMCsGA1UECxMkRXF1aWZheCBTZWN1cmUgQ2Vy
7
+ dGlmaWNhdGUgQXV0aG9yaXR5MB4XDTk4MDgyMjE2NDE1MVoXDTE4MDgyMjE2NDE1
8
+ MVowTjELMAkGA1UEBhMCVVMxEDAOBgNVBAoTB0VxdWlmYXgxLTArBgNVBAsTJEVx
9
+ dWlmYXggU2VjdXJlIENlcnRpZmljYXRlIEF1dGhvcml0eTCBnzANBgkqhkiG9w0B
10
+ AQEFAAOBjQAwgYkCgYEAwV2xWGcIYu6gmi0fCG2RFGiYCh7+2gRvE4RiIcPRfM6f
11
+ BeC4AfBONOziipUEZKzxa1NfBbPLZ4C/QgKO/t0BCezhABRP/PvwDN1Dulsr4R+A
12
+ cJkVV5MW8Q+XarfCaCMczE1ZMKxRHjuvK9buY0V7xdlfUNLjUA86iOe/FP3gx7kC
13
+ AwEAAaOCAQkwggEFMHAG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dVwjOLVDmEjIWE4ry
49
+ lKKbR6iGf9mY5ffldnRk2JG8hBYo2CVEMH6C2Kyx5MDkFWzbtiQnAioBEoW6MYhY
50
+ R3TjuNJkpsMyWS4pS0XxW4lJLoKaxhgVRNAuZAEVaDj59vlmAwxVG52/AECu8Egn
51
+ TOCAXi25KhV6vGb4NQ==
52
+ -----END CERTIFICATE-----
53
+
54
+ Country: US
55
+ Organization: GeoTrust Inc.
56
+ Common Name: GeoTrust SSL CA - G2
57
+ -----BEGIN CERTIFICATE-----
58
+ MIIDfTCCAuagAwIBAgIDErvmMA0GCSqGSIb3DQEBBQUAME4xCzAJBgNVBAYTAlVT
59
+ MRAwDgYDVQQKEwdFcXVpZmF4MS0wKwYDVQQLEyRFcXVpZmF4IFNlY3VyZSBDZXJ0
60
+ aWZpY2F0ZSBBdXRob3JpdHkwHhcNMDIwNTIxMDQwMDAwWhcNMTgwODIxMDQwMDAw
61
+ WjBCMQswCQYDVQQGEwJVUzEWMBQGA1UEChMNR2VvVHJ1c3QgSW5jLjEbMBkGA1UE
62
+ AxMSR2VvVHJ1c3QgR2xvYmFsIENBMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB
63
+ CgKCAQEA2swYYzD99BcjGlZ+W988bDjkcbd4kdS8odhM+KhDtgPpTSEHCIjaWC9m
64
+ OSm9BXiLnTjoBbdqfnGk5sRgprDvgOSJKA+eJdbtg/OtppHHmMlCGDUUna2YRpIu
65
+ T8rxh0PBFpVXLVDviS2Aelet8u5fa9IAjbkU+BQVNdnARqN7csiRv8lVK83Qlz6c
66
+ JmTM386DGXHKTubU1XupGc1V3sjs0l44U+VcT4wt/lAjNvxm5suOpDkZALeVAjmR
67
+ Cw7+OC7RHQWa9k0+bw8HHa8sHo9gOeL6NlMTOdReJivbPagUvTLrGAMoUgRx5asz
68
+ PeE4uwc2hGKceeoWMPRfwCvocWvk+QIDAQABo4HwMIHtMB8GA1UdIwQYMBaAFEjm
69
+ aPkr0rKV10fYIyAQTzOYkJ/UMB0GA1UdDgQWBBTAephojYn7qwVkDBF9qn1luMrM
70
+ TjAPBgNVHRMBAf8EBTADAQH/MA4GA1UdDwEB/wQEAwIBBjA6BgNVHR8EMzAxMC+g
71
+ LaArhilodHRwOi8vY3JsLmdlb3RydXN0LmNvbS9jcmxzL3NlY3VyZWNhLmNybDBO
72
+ BgNVHSAERzBFMEMGBFUdIAAwOzA5BggrBgEFBQcCARYtaHR0cHM6Ly93d3cuZ2Vv
73
+ dHJ1c3QuY29tL3Jlc291cmNlcy9yZXBvc2l0b3J5MA0GCSqGSIb3DQEBBQUAA4GB
74
+ AHbhEm5OSxYShjAGsoEIz/AIx8dxfmbuwu3UOx//8PDITtZDOLC5MH0Y0FWDomrL
75
+ NhGc6Ehmo21/uBPUR/6LWlxz/K7ZGzIZOKuXNBSqltLroxwUCEm2u+WR74M26x1W
76
+ b8ravHNjkOR/ez4iyz0H7V84dJzjA1BOoa+Y7mHyhD8S
77
+ -----END CERTIFICATE-----
78
+
79
+ Country: US
80
+ Organization: GeoTrust Inc.
81
+ Common Name: GeoTrust SSL CA - G3
82
+ -----BEGIN CERTIFICATE-----
83
+ MIID/jCCAuagAwIBAgIQFaxulBmyeUtB9iepwxgPHzANBgkqhkiG9w0BAQsFADCB
84
+ mDELMAkGA1UEBhMCVVMxFjAUBgNVBAoTDUdlb1RydXN0IEluYy4xOTA3BgNVBAsT
85
+ MChjKSAyMDA4IEdlb1RydXN0IEluYy4gLSBGb3IgYXV0aG9yaXplZCB1c2Ugb25s
86
+ eTE2MDQGA1UEAxMtR2VvVHJ1c3QgUHJpbWFyeSBDZXJ0aWZpY2F0aW9uIEF1dGhv
87
+ cml0eSAtIEczMB4XDTA4MDQwMjAwMDAwMFoXDTM3MTIwMTIzNTk1OVowgZgxCzAJ
88
+ BgNVBAYTAlVTMRYwFAYDVQQKEw1HZW9UcnVzdCBJbmMuMTkwNwYDVQQLEzAoYykg
89
+ MjAwOCBHZW9UcnVzdCBJbmMuIC0gRm9yIGF1dGhvcml6ZWQgdXNlIG9ubHkxNjA0
90
+ BgNVBAMTLUdlb1RydXN0IFByaW1hcnkgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkg
91
+ LSBHMzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBANziXmJYHTNXOTIz
92
+ +uvLh4yn1ErdBojqZI4xmKU4kB6Yzy5jK/BGvESyiaHAKAxJcCGVn2TAppMSAmUm
93
+ hsalifD614SgcK9PGpc/BkTVyetyEH3kMSj7HGHmKAdEc5IiaacDiGydY8hS2pgn
94
+ 5whMcD60yRLBxWeDXTPzAxHsatBT4tG6NmCUgLthY2xbF37fQJQeqw3CIShwiP/W
95
+ JmxsYAQlTlV+fe+/lEjetx3dcI0FX4ilm/LC7urRQEFtYjgdVgbFA0dRIBn8exAL
96
+ DmKudlW/X3e+PkkBUz2YJQN2JFodtNuJ6nnltrM7P7pMKEF/BqxqjsHQ9gUdfeZC
97
+ huOl1UcCAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMCAQYw
98
+ HQYDVR0OBBYEFMR5yo6hTgMdHNxr2zFblD4/MH8tMA0GCSqGSIb3DQEBCwUAA4IB
99
+ AQAtxRPPVoB7eni9n64smefv2t+UXglpp+duaIy9cr5HqQ6XErhK8WTTOd8lNNTB
100
+ zU6B8A8ExCSzNJbGpqow32hhc9f5joWJ7w5elShKKiePEI4ufIbEAp7aDHdlDkQN
101
+ kv39sxY2+hENHYwOB4lqKVb3cvTdFZx3NWZXqxNT2I7BQMXXExZacse3aQHEerGD
102
+ AWh9jUGhlBjBJVz88P6DAod8DQ3PLghcSkANPuyBYeYk28rgDi0Hsj5W3I31QYUH
103
+ SJsMC8tJP33st/3LjWeJGqvtux6jAAgIFyqCXDFdRootD4abdNlF+9RAsXqqaC2G
104
+ spki4cErx5z481+oghLrGREt
105
+ -----END CERTIFICATE-----
@@ -0,0 +1,6 @@
1
+ require "omise/all"
2
+ require "omise/version"
3
+
4
+ module Omise
5
+ LIB_PATH = File.expand_path("../", __FILE__)
6
+ end
@@ -0,0 +1,8 @@
1
+ require "omise/object"
2
+
3
+ module Omise
4
+ class Account < OmiseObject
5
+ self.endpoint = "/account"
6
+ singleton!
7
+ end
8
+ end
@@ -0,0 +1,9 @@
1
+ require "omise/account"
2
+ require "omise/balance"
3
+ require "omise/card"
4
+ require "omise/charge"
5
+ require "omise/customer"
6
+ require "omise/refund"
7
+ require "omise/token"
8
+ require "omise/transaction"
9
+ require "omise/transfer"
@@ -0,0 +1,63 @@
1
+ require "omise/util"
2
+
3
+ module Omise
4
+ module Attributes
5
+ def initialize(attributes = {})
6
+ @attributes = attributes
7
+ end
8
+
9
+ def attributes
10
+ @attributes
11
+ end
12
+
13
+ def assign_attributes(attributes = {})
14
+ @attributes = attributes
15
+ cleanup!
16
+ yield if block_given?
17
+ self
18
+ end
19
+
20
+ def location(id = nil)
21
+ [@attributes["location"], id].compact.join("/")
22
+ end
23
+
24
+ def destroyed?
25
+ @attributes["deleted"]
26
+ end
27
+
28
+ def as_json(*)
29
+ @attributes
30
+ end
31
+
32
+ def [](key)
33
+ value = @attributes[key.to_s]
34
+ if value.is_a?(Hash)
35
+ @attributes[key.to_s] = Omise::Util.typecast(value)
36
+ else
37
+ value
38
+ end
39
+ end
40
+
41
+ def key?(key)
42
+ @attributes.key?(key.to_s)
43
+ end
44
+
45
+ def respond_to?(method_name)
46
+ key?(method_name) || super
47
+ end
48
+
49
+ def method_missing(method_name, *args, &block)
50
+ if key?(method_name)
51
+ self[method_name]
52
+ else
53
+ super
54
+ end
55
+ end
56
+
57
+ private
58
+
59
+ def cleanup!
60
+ # noop
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,8 @@
1
+ require "omise/object"
2
+
3
+ module Omise
4
+ class Balance < OmiseObject
5
+ self.endpoint = "/balance"
6
+ singleton!
7
+ end
8
+ end
@@ -0,0 +1,19 @@
1
+ require "omise/object"
2
+
3
+ module Omise
4
+ class Card < OmiseObject
5
+ self.endpoint = "/cards"
6
+
7
+ def reload(attributes = {})
8
+ assign_attributes resource(attributes).get
9
+ end
10
+
11
+ def update(attributes = {})
12
+ assign_attributes resource(attributes).patch(attributes)
13
+ end
14
+
15
+ def destroy(attributes = {})
16
+ assign_attributes resource(attributes).delete
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,22 @@
1
+ require "omise/list"
2
+ require "omise/card"
3
+ require "omise/token"
4
+
5
+ module Omise
6
+ class CardList < List
7
+ def initialize(customer, attributes = {})
8
+ super(attributes)
9
+ @customer = customer
10
+ end
11
+
12
+ def retrieve(id, attributes = {})
13
+ Card.new self.class.resource(location(id), attributes).get
14
+ end
15
+
16
+ def create(attributes = {})
17
+ token = Token.create(card: attributes)
18
+ @customer.update(card: token.id)
19
+ retrieve(token.card.id)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,55 @@
1
+ require "omise/object"
2
+ require "omise/list"
3
+ require "omise/customer"
4
+ require "omise/refund_list"
5
+ require "omise/transaction"
6
+
7
+ module Omise
8
+ class Charge < OmiseObject
9
+ self.endpoint = "/charges"
10
+
11
+ def self.retrieve(id, attributes = {})
12
+ new resource(location(id), attributes).get
13
+ end
14
+
15
+ def self.list(attributes = {})
16
+ List.new resource(location, attributes).get
17
+ end
18
+
19
+ def self.create(attributes = {})
20
+ new resource(location, attributes).post(attributes)
21
+ end
22
+
23
+ def reload(attributes = {})
24
+ assign_attributes resource(attributes).get
25
+ end
26
+
27
+ def update(attributes = {})
28
+ assign_attributes resource(attributes).patch(attributes)
29
+ end
30
+
31
+ def customer(options = {})
32
+ if @attributes["customer"]
33
+ @customer ||= Customer.retrieve(@attributes["customer"], options)
34
+ end
35
+ end
36
+
37
+ def transaction(options = {})
38
+ if @attributes["customer"]
39
+ @transaction ||= Transaction.retrieve(@attributes["transaction"], options)
40
+ end
41
+ end
42
+
43
+ def refunds
44
+ @refunds ||= RefundList.new(self, @attributes["refunds"])
45
+ end
46
+
47
+ private
48
+
49
+ def cleanup!
50
+ @refunds = nil
51
+ @customer = nil
52
+ @transaction = nil
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,36 @@
1
+ require "omise/resource"
2
+
3
+ module Omise
4
+ class << self
5
+ attr_writer :api_key, :vault_key
6
+ attr_accessor :api_url, :vault_url, :api_version, :resource
7
+
8
+ def api_key
9
+ get_key :api
10
+ end
11
+
12
+ def vault_key
13
+ get_key :vault
14
+ end
15
+
16
+ def test!
17
+ require "omise/testing/resource"
18
+ self.resource = Omise::Testing::Resource
19
+ end
20
+
21
+ private
22
+
23
+ def get_key(name)
24
+ if key = instance_variable_get("@#{name}_key")
25
+ key
26
+ else
27
+ raise "Set Omise.#{name}_key to use this feature"
28
+ end
29
+ end
30
+ end
31
+
32
+ self.api_url = "https://api.omise.co"
33
+ self.vault_url = "https://vault.omise.co"
34
+ self.api_version = "2014-07-27"
35
+ self.resource = Resource
36
+ end