omise 0.1.5 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -2
- data/README.md +17 -1
- data/lib/omise/attributes.rb +20 -3
- data/lib/omise/charge.rb +13 -16
- data/lib/omise/config.rb +0 -1
- data/lib/omise/customer.rb +2 -11
- data/lib/omise/dispute.rb +1 -9
- data/lib/omise/object.rb +4 -0
- data/lib/omise/recipient.rb +1 -9
- data/lib/omise/refund.rb +2 -13
- data/lib/omise/resource.rb +30 -6
- data/lib/omise/testing/resource.rb +13 -3
- data/lib/omise/transfer.rb +3 -14
- data/lib/omise/util.rb +2 -1
- data/lib/omise/version.rb +1 -1
- data/test/fixtures/api.omise.co/charges/chrg_test_4yq7duw15p9hdrjp8oq-get-expand-true.json +96 -0
- data/test/fixtures/api.omise.co/charges/chrg_test_4yq7duw15p9hdrjp8oq/capture-post.json +58 -0
- data/test/omise/test_account.rb +2 -2
- data/test/omise/test_balance.rb +2 -2
- data/test/omise/test_card.rb +2 -2
- data/test/omise/test_charge.rb +46 -2
- data/test/omise/test_customer.rb +2 -2
- data/test/omise/test_dispute.rb +2 -2
- data/test/omise/test_recipient.rb +2 -2
- data/test/omise/test_refund.rb +2 -2
- data/test/omise/test_resource.rb +36 -0
- data/test/omise/test_token.rb +2 -2
- data/test/omise/test_transaction.rb +2 -2
- data/test/omise/test_transfer.rb +2 -2
- data/test/support.rb +21 -5
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 071c06e6a320fa5d993a2291f62c985b982c1eda
|
4
|
+
data.tar.gz: 4021e157e6f3b623ca960fd7aaec603b5a63c7c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a7485c139f8ae933527c487a17cf48eb0ce8053a3e9c99784ed7b8370cf976c7d5d43b5e10fe313ee392b6e4e02e89e153b0517a91b9ad5ea4eed15283b8f9e
|
7
|
+
data.tar.gz: bc402a2ba97a6eff222c2a606840e1741c3862c604ed4da884bf58b5403ed700ef7da3b57e9c84ee6fdad1803bc8f629f043a8db892a66297f906a80b1ec1615
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,13 @@
|
|
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.2.0] 2015-11-13
|
6
|
+
|
7
|
+
- [Added] Add Omise-Version header to request.
|
8
|
+
- [Fixed] Fix auto expanding attribute does not play well with expand=true.
|
9
|
+
- [Fixed] Fix bank accounts were typecasted as OmiseObject instead of being
|
10
|
+
typecasted as BankAccount.
|
11
|
+
|
5
12
|
## [0.1.5] 2015-07-29
|
6
13
|
|
7
14
|
- [Added] Add json dependency in the gemspec.
|
@@ -14,10 +21,12 @@ An [unreleased] version is not available on rubygems and is subject to changes a
|
|
14
21
|
## [0.1.0] 2015-01-19
|
15
22
|
|
16
23
|
- [Added] Add support for the Refund API.
|
17
|
-
- [Added] Add a test suite that can be run locally without the need for a
|
24
|
+
- [Added] Add a test suite that can be run locally without the need for a
|
25
|
+
network connection or to set Omise keys.
|
18
26
|
- [Added] Add a list method to retrieve a list of objects.
|
19
27
|
- [Changed] Move typecast and load_response methods into a Util module.
|
20
|
-
- [Removed] Remove the ability to retrieve a list by calling retrieve without
|
28
|
+
- [Removed] Remove the ability to retrieve a list by calling retrieve without
|
29
|
+
arguments.
|
21
30
|
|
22
31
|
## [0.0.1] - 2014-11-18
|
23
32
|
|
data/README.md
CHANGED
@@ -43,6 +43,22 @@ create tokens. When creating a token server side you'll need card data
|
|
43
43
|
transiting to and from your server and this requires that your organization be
|
44
44
|
PCI compliant.
|
45
45
|
|
46
|
+
### API version
|
47
|
+
|
48
|
+
In case you want to enforce API version the application use, you can specify it
|
49
|
+
by setting the api_version. The version specified by this settings will override
|
50
|
+
the version setting in your account. This is useful if you have multiple
|
51
|
+
environments with different API versions (e.g. development on the latest but
|
52
|
+
production on the older version).
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
require "omise"
|
56
|
+
Omise.api_version = "2014-07-27"
|
57
|
+
```
|
58
|
+
|
59
|
+
It is highly recommended to set this version to the current version
|
60
|
+
you're using.
|
61
|
+
|
46
62
|
## Quick Start
|
47
63
|
|
48
64
|
After you have implemented [Omise.js](https://gitub.com/omise/omise.js) on your
|
@@ -56,7 +72,7 @@ charge = Omise::Charge.create({
|
|
56
72
|
card: params[:omise_token]
|
57
73
|
})
|
58
74
|
|
59
|
-
if charge.
|
75
|
+
if charge.paid
|
60
76
|
# handle success
|
61
77
|
puts "thanks"
|
62
78
|
else
|
data/lib/omise/attributes.rb
CHANGED
@@ -3,6 +3,7 @@ require "omise/util"
|
|
3
3
|
module Omise
|
4
4
|
module Attributes
|
5
5
|
def initialize(attributes = {})
|
6
|
+
@expanded_attributes = {}
|
6
7
|
@attributes = attributes
|
7
8
|
end
|
8
9
|
|
@@ -11,8 +12,8 @@ module Omise
|
|
11
12
|
end
|
12
13
|
|
13
14
|
def assign_attributes(attributes = {})
|
14
|
-
@attributes = attributes
|
15
15
|
cleanup!
|
16
|
+
@attributes = attributes
|
16
17
|
yield if block_given?
|
17
18
|
self
|
18
19
|
end
|
@@ -32,7 +33,7 @@ module Omise
|
|
32
33
|
def [](key)
|
33
34
|
value = @attributes[key.to_s]
|
34
35
|
if value.is_a?(Hash)
|
35
|
-
|
36
|
+
Omise::Util.typecast(value)
|
36
37
|
else
|
37
38
|
value
|
38
39
|
end
|
@@ -56,8 +57,24 @@ module Omise
|
|
56
57
|
|
57
58
|
private
|
58
59
|
|
60
|
+
def lookup_attribute_value(*keys)
|
61
|
+
keys.each { |key| return self[key] if key?(key) }
|
62
|
+
end
|
63
|
+
|
64
|
+
def list_attribute(klass, key)
|
65
|
+
klass.new(self, @attributes[key])
|
66
|
+
end
|
67
|
+
|
68
|
+
def expand_attribute(object, key, options = {})
|
69
|
+
if @attributes[key] && @attributes[key].is_a?(String)
|
70
|
+
@expanded_attributes[key] ||= object.retrieve(@attributes[key], options)
|
71
|
+
else
|
72
|
+
self[key]
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
59
76
|
def cleanup!
|
60
|
-
|
77
|
+
@expanded_attributes = {}
|
61
78
|
end
|
62
79
|
end
|
63
80
|
end
|
data/lib/omise/charge.rb
CHANGED
@@ -29,35 +29,32 @@ module Omise
|
|
29
29
|
assign_attributes resource(attributes).patch(attributes)
|
30
30
|
end
|
31
31
|
|
32
|
+
def capture(options = {})
|
33
|
+
assign_attributes nested_resource("capture", options).post
|
34
|
+
end
|
35
|
+
|
32
36
|
def customer(options = {})
|
33
|
-
|
34
|
-
@customer ||= Customer.retrieve(@attributes["customer"], options)
|
35
|
-
end
|
37
|
+
expand_attribute Customer, "customer", options
|
36
38
|
end
|
37
39
|
|
38
40
|
def dispute(options = {})
|
39
|
-
|
40
|
-
@dispute ||= Dispute.retrieve(@attributes["dispute"], options)
|
41
|
-
end
|
41
|
+
expand_attribute Dispute, "dispute", options
|
42
42
|
end
|
43
43
|
|
44
44
|
def transaction(options = {})
|
45
|
-
|
46
|
-
@transaction ||= Transaction.retrieve(@attributes["transaction"], options)
|
47
|
-
end
|
45
|
+
expand_attribute Transaction, "transaction", options
|
48
46
|
end
|
49
47
|
|
50
48
|
def refunds
|
51
|
-
|
49
|
+
list_attribute RefundList, "refunds"
|
52
50
|
end
|
53
51
|
|
54
|
-
|
52
|
+
def captured
|
53
|
+
lookup_attribute_value :captured, :paid
|
54
|
+
end
|
55
55
|
|
56
|
-
def
|
57
|
-
|
58
|
-
@dispute = nil
|
59
|
-
@refunds = nil
|
60
|
-
@transaction = nil
|
56
|
+
def paid
|
57
|
+
lookup_attribute_value :paid, :captured
|
61
58
|
end
|
62
59
|
end
|
63
60
|
end
|
data/lib/omise/config.rb
CHANGED
data/lib/omise/customer.rb
CHANGED
@@ -31,20 +31,11 @@ module Omise
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def default_card(options = {})
|
34
|
-
|
35
|
-
@default_card ||= cards.retrieve(@attributes["default_card"], options)
|
36
|
-
end
|
34
|
+
expand_attribute cards, "default_card", options
|
37
35
|
end
|
38
36
|
|
39
37
|
def cards
|
40
|
-
|
41
|
-
end
|
42
|
-
|
43
|
-
private
|
44
|
-
|
45
|
-
def cleanup!
|
46
|
-
@default_card = nil
|
47
|
-
@cards = nil
|
38
|
+
list_attribute CardList, "cards"
|
48
39
|
end
|
49
40
|
end
|
50
41
|
end
|
data/lib/omise/dispute.rb
CHANGED
@@ -24,15 +24,7 @@ module Omise
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def charge(options = {})
|
27
|
-
|
28
|
-
@charge ||= Charge.retrieve(@attributes["charge"], options)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
private
|
33
|
-
|
34
|
-
def cleanup!
|
35
|
-
@charge = nil
|
27
|
+
expand_attribute Charge, "charge", options
|
36
28
|
end
|
37
29
|
end
|
38
30
|
end
|
data/lib/omise/object.rb
CHANGED
data/lib/omise/recipient.rb
CHANGED
@@ -30,15 +30,7 @@ module Omise
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def bank_account
|
33
|
-
|
34
|
-
@bank_account ||= BankAccount.new(@attributes["bank_account"])
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
def cleanup!
|
41
|
-
@bank_account = nil
|
33
|
+
expand_attribute BankAccount, "bank_account"
|
42
34
|
end
|
43
35
|
end
|
44
36
|
end
|
data/lib/omise/refund.rb
CHANGED
@@ -11,22 +11,11 @@ module Omise
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def charge(options = {})
|
14
|
-
|
15
|
-
@charge ||= Charge.retrieve(@attributes["charge"], options)
|
16
|
-
end
|
14
|
+
expand_attribute Charge, "charge", options
|
17
15
|
end
|
18
16
|
|
19
17
|
def transaction(options = {})
|
20
|
-
|
21
|
-
@transaction ||= Transaction.retrieve(@attributes["transaction"], options)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
private
|
26
|
-
|
27
|
-
def cleanup!
|
28
|
-
@charge = nil
|
29
|
-
@transaction = nil
|
18
|
+
expand_attribute Transaction, "transaction", options
|
30
19
|
end
|
31
20
|
end
|
32
21
|
end
|
data/lib/omise/resource.rb
CHANGED
@@ -6,24 +6,30 @@ require "rest-client"
|
|
6
6
|
require "omise/util"
|
7
7
|
require "omise/config"
|
8
8
|
require "omise/error"
|
9
|
+
require "omise/version"
|
9
10
|
|
10
11
|
module Omise
|
11
12
|
class Resource
|
12
13
|
CA_BUNDLE_PATH = File.expand_path("../../../data/ca_certificates.pem", __FILE__)
|
14
|
+
DEFAULT_HEADERS = {
|
15
|
+
user_agent: "OmiseRuby/#{Omise::VERSION} Ruby/#{RUBY_VERSION}"
|
16
|
+
}
|
13
17
|
|
14
18
|
def initialize(url, path, key)
|
15
|
-
@uri =
|
16
|
-
@
|
17
|
-
@
|
19
|
+
@uri = prepare_uri(url, path)
|
20
|
+
@headers = prepare_headers
|
21
|
+
@key = key
|
22
|
+
|
23
|
+
@resource = RestClient::Resource.new(@uri, {
|
18
24
|
user: key,
|
19
25
|
verify_ssl: OpenSSL::SSL::VERIFY_PEER,
|
20
26
|
ssl_ca_file: CA_BUNDLE_PATH,
|
21
|
-
headers:
|
22
|
-
user_agent: "OmiseRuby/#{Omise::VERSION} OmiseAPI/#{Omise.api_version} Ruby/#{RUBY_VERSION}"
|
23
|
-
}
|
27
|
+
headers: @headers,
|
24
28
|
})
|
25
29
|
end
|
26
30
|
|
31
|
+
attr_reader :uri, :headers, :key
|
32
|
+
|
27
33
|
def get(attributes = {})
|
28
34
|
@resource.get(params: attributes) { |r| Omise::Util.load_response(r) }
|
29
35
|
end
|
@@ -39,5 +45,23 @@ module Omise
|
|
39
45
|
def delete
|
40
46
|
@resource.delete { |r| Omise::Util.load_response(r) }
|
41
47
|
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def prepare_uri(url, path)
|
52
|
+
uri = URI.parse(url)
|
53
|
+
uri.path = [uri.path, path].join
|
54
|
+
uri.to_s
|
55
|
+
end
|
56
|
+
|
57
|
+
def prepare_headers
|
58
|
+
headers = {}.merge(DEFAULT_HEADERS)
|
59
|
+
|
60
|
+
if Omise.api_version
|
61
|
+
headers = headers.merge(omise_version: Omise.api_version)
|
62
|
+
end
|
63
|
+
|
64
|
+
headers
|
65
|
+
end
|
42
66
|
end
|
43
67
|
end
|
@@ -12,7 +12,7 @@ module Omise
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def get(attributes = {})
|
15
|
-
Omise::Util.load_response(read_file("get"))
|
15
|
+
Omise::Util.load_response(read_file("get", attributes))
|
16
16
|
end
|
17
17
|
|
18
18
|
def patch(attributes = {})
|
@@ -27,10 +27,20 @@ module Omise
|
|
27
27
|
Omise::Util.load_response(read_file("post"))
|
28
28
|
end
|
29
29
|
|
30
|
-
|
30
|
+
private
|
31
|
+
|
32
|
+
def generate_path(verb, attributes)
|
33
|
+
return verb if attributes.empty?
|
34
|
+
params = attributes.to_a.sort { |x,y| x.first <=> x.last }.flatten.join("-")
|
35
|
+
[verb, params].compact.join("-")
|
36
|
+
end
|
37
|
+
|
38
|
+
def read_file(verb, attributes = {})
|
39
|
+
path = generate_path(verb, attributes)
|
40
|
+
|
31
41
|
File.read(File.expand_path(File.join(
|
32
42
|
Omise::LIB_PATH, "..", "test", "fixtures",
|
33
|
-
[@uri.host, @uri.path, "-#{
|
43
|
+
[@uri.host, @uri.path, "-#{path}.json"].join
|
34
44
|
)))
|
35
45
|
end
|
36
46
|
end
|
data/lib/omise/transfer.rb
CHANGED
@@ -31,23 +31,12 @@ module Omise
|
|
31
31
|
assign_attributes resource(attributes).delete
|
32
32
|
end
|
33
33
|
|
34
|
-
def recipient
|
35
|
-
|
36
|
-
@recipient ||= Recipient.retrieve(@attributes["recipient"])
|
37
|
-
end
|
34
|
+
def recipient(options = {})
|
35
|
+
expand_attribute Recipient, "recipient", options
|
38
36
|
end
|
39
37
|
|
40
38
|
def bank_account
|
41
|
-
|
42
|
-
@bank_account ||= BankAccount.new(@attributes["bank_account"])
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
private
|
47
|
-
|
48
|
-
def cleanup!
|
49
|
-
@bank_account = nil
|
50
|
-
@recipient = nil
|
39
|
+
expand_attribute BankAccount, "bank_account"
|
51
40
|
end
|
52
41
|
end
|
53
42
|
end
|
data/lib/omise/util.rb
CHANGED
@@ -7,7 +7,8 @@ module Omise
|
|
7
7
|
module Util module_function
|
8
8
|
def typecast(object)
|
9
9
|
klass = begin
|
10
|
-
|
10
|
+
klass_name = object["object"].split("_").map(&:capitalize).join("")
|
11
|
+
Omise.const_get(klass_name)
|
11
12
|
rescue NameError
|
12
13
|
OmiseObject
|
13
14
|
end
|
data/lib/omise/version.rb
CHANGED
@@ -0,0 +1,96 @@
|
|
1
|
+
{
|
2
|
+
"object": "charge",
|
3
|
+
"id": "chrg_test_4yq7duw15p9hdrjp8oq",
|
4
|
+
"livemode": false,
|
5
|
+
"location": "/charges/chrg_test_4yq7duw15p9hdrjp8oq",
|
6
|
+
"amount": 100000,
|
7
|
+
"currency": "thb",
|
8
|
+
"description": "Charge for order 3947",
|
9
|
+
"capture": true,
|
10
|
+
"authorized": true,
|
11
|
+
"captured": true,
|
12
|
+
"transaction": "trxn_test_4yq7duwb9jts1vxgqua",
|
13
|
+
"refunded": 10000,
|
14
|
+
"refunds": {
|
15
|
+
"object": "list",
|
16
|
+
"from": "1970-01-01T00:00:00+00:00",
|
17
|
+
"to": "2015-01-16T07:23:49+00:00",
|
18
|
+
"offset": 0,
|
19
|
+
"limit": 20,
|
20
|
+
"total": 1,
|
21
|
+
"data": [
|
22
|
+
{
|
23
|
+
"object": "refund",
|
24
|
+
"id": "rfnd_test_4yqmv79ahghsiz23y3c",
|
25
|
+
"location": "/charges/chrg_test_4yq7duw15p9hdrjp8oq/refunds/rfnd_test_4yqmv79ahghsiz23y3c",
|
26
|
+
"amount": 10000,
|
27
|
+
"currency": "thb",
|
28
|
+
"charge": "chrg_test_4yq7duw15p9hdrjp8oq",
|
29
|
+
"transaction": "trxn_test_4yqmv79fzpy0gmz5mmq",
|
30
|
+
"created": "2015-01-16T07:23:45Z"
|
31
|
+
}
|
32
|
+
],
|
33
|
+
"location": "/charges/chrg_test_4yq7duw15p9hdrjp8oq/refunds"
|
34
|
+
},
|
35
|
+
"failure_code": null,
|
36
|
+
"failure_message": null,
|
37
|
+
"card": {
|
38
|
+
"object": "card",
|
39
|
+
"id": "card_test_4yq6tuucl9h4erukfl0",
|
40
|
+
"livemode": false,
|
41
|
+
"location": "/customers/cust_test_4yq6txdpfadhbaqnwp3/cards/card_test_4yq6tuucl9h4erukfl0",
|
42
|
+
"country": "",
|
43
|
+
"city": "Bangkok",
|
44
|
+
"postal_code": "10320",
|
45
|
+
"financing": "",
|
46
|
+
"last_digits": "4242",
|
47
|
+
"brand": "Visa",
|
48
|
+
"expiration_month": 1,
|
49
|
+
"expiration_year": 2017,
|
50
|
+
"fingerprint": "sRF/oMw2UQJJp/WbU+2/ZbVzwROjpMf1lyhOHhOqziw=",
|
51
|
+
"name": "JOHN DOE",
|
52
|
+
"security_code_check": true,
|
53
|
+
"created": "2015-01-15T04:03:40Z"
|
54
|
+
},
|
55
|
+
"customer": {
|
56
|
+
"object": "customer",
|
57
|
+
"id": "cust_test_4yq6txdpfadhbaqnwp3",
|
58
|
+
"livemode": false,
|
59
|
+
"location": "/customers/cust_test_4yq6txdpfadhbaqnwp3",
|
60
|
+
"default_card": "card_test_4yq6tuucl9h4erukfl0",
|
61
|
+
"email": "john.doe@example.com",
|
62
|
+
"description": "John Doe (id: 30)",
|
63
|
+
"created": "2015-01-15T04:03:52Z",
|
64
|
+
"cards": {
|
65
|
+
"object": "list",
|
66
|
+
"from": "1970-01-01T00:00:00+00:00",
|
67
|
+
"to": "2015-01-15T04:03:52+00:00",
|
68
|
+
"offset": 0,
|
69
|
+
"limit": 20,
|
70
|
+
"total": 1,
|
71
|
+
"data": [
|
72
|
+
{
|
73
|
+
"object": "card",
|
74
|
+
"id": "card_test_4yq6tuucl9h4erukfl0",
|
75
|
+
"livemode": false,
|
76
|
+
"location": "/customers/cust_test_4yq6txdpfadhbaqnwp3/cards/card_test_4yq6tuucl9h4erukfl0",
|
77
|
+
"country": "",
|
78
|
+
"city": "Bangkok",
|
79
|
+
"postal_code": "10320",
|
80
|
+
"financing": "",
|
81
|
+
"last_digits": "4242",
|
82
|
+
"brand": "Visa",
|
83
|
+
"expiration_month": 1,
|
84
|
+
"expiration_year": 2017,
|
85
|
+
"fingerprint": "sRF/oMw2UQJJp/WbU+2/ZbVzwROjpMf1lyhOHhOqziw=",
|
86
|
+
"name": "JOHN DOE",
|
87
|
+
"security_code_check": true,
|
88
|
+
"created": "2015-01-15T04:03:40Z"
|
89
|
+
}
|
90
|
+
],
|
91
|
+
"location": "/customers/cust_test_4yq6txdpfadhbaqnwp3/cards"
|
92
|
+
}
|
93
|
+
},
|
94
|
+
"ip": null,
|
95
|
+
"created": "2015-01-15T05:00:29Z"
|
96
|
+
}
|
@@ -0,0 +1,58 @@
|
|
1
|
+
{
|
2
|
+
"object": "charge",
|
3
|
+
"id": "chrg_test_4yq7duw15p9hdrjp8oq",
|
4
|
+
"livemode": false,
|
5
|
+
"location": "/charges/chrg_test_4yq7duw15p9hdrjp8oq",
|
6
|
+
"amount": 100000,
|
7
|
+
"currency": "thb",
|
8
|
+
"description": "Charge for order 3947",
|
9
|
+
"capture": true,
|
10
|
+
"authorized": true,
|
11
|
+
"captured": true,
|
12
|
+
"transaction": "trxn_test_4yq7duwb9jts1vxgqua",
|
13
|
+
"refunded": 10000,
|
14
|
+
"refunds": {
|
15
|
+
"object": "list",
|
16
|
+
"from": "1970-01-01T00:00:00+00:00",
|
17
|
+
"to": "2015-01-16T07:23:49+00:00",
|
18
|
+
"offset": 0,
|
19
|
+
"limit": 20,
|
20
|
+
"total": 1,
|
21
|
+
"data": [
|
22
|
+
{
|
23
|
+
"object": "refund",
|
24
|
+
"id": "rfnd_test_4yqmv79ahghsiz23y3c",
|
25
|
+
"location": "/charges/chrg_test_4yq7duw15p9hdrjp8oq/refunds/rfnd_test_4yqmv79ahghsiz23y3c",
|
26
|
+
"amount": 10000,
|
27
|
+
"currency": "thb",
|
28
|
+
"charge": "chrg_test_4yq7duw15p9hdrjp8oq",
|
29
|
+
"transaction": "trxn_test_4yqmv79fzpy0gmz5mmq",
|
30
|
+
"created": "2015-01-16T07:23:45Z"
|
31
|
+
}
|
32
|
+
],
|
33
|
+
"location": "/charges/chrg_test_4yq7duw15p9hdrjp8oq/refunds"
|
34
|
+
},
|
35
|
+
"failure_code": null,
|
36
|
+
"failure_message": null,
|
37
|
+
"card": {
|
38
|
+
"object": "card",
|
39
|
+
"id": "card_test_4yq6tuucl9h4erukfl0",
|
40
|
+
"livemode": false,
|
41
|
+
"location": "/customers/cust_test_4yq6txdpfadhbaqnwp3/cards/card_test_4yq6tuucl9h4erukfl0",
|
42
|
+
"country": "",
|
43
|
+
"city": "Bangkok",
|
44
|
+
"postal_code": "10320",
|
45
|
+
"financing": "",
|
46
|
+
"last_digits": "4242",
|
47
|
+
"brand": "Visa",
|
48
|
+
"expiration_month": 1,
|
49
|
+
"expiration_year": 2017,
|
50
|
+
"fingerprint": "sRF/oMw2UQJJp/WbU+2/ZbVzwROjpMf1lyhOHhOqziw=",
|
51
|
+
"name": "JOHN DOE",
|
52
|
+
"security_code_check": true,
|
53
|
+
"created": "2015-01-15T04:03:40Z"
|
54
|
+
},
|
55
|
+
"customer": "cust_test_4yq6txdpfadhbaqnwp3",
|
56
|
+
"ip": null,
|
57
|
+
"created": "2015-01-15T05:00:29Z"
|
58
|
+
}
|
data/test/omise/test_account.rb
CHANGED
data/test/omise/test_balance.rb
CHANGED
data/test/omise/test_card.rb
CHANGED
data/test/omise/test_charge.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require "support"
|
2
2
|
|
3
|
-
class TestCharge <
|
4
|
-
|
3
|
+
class TestCharge < Omise::Test
|
4
|
+
setup do
|
5
5
|
@charge = Omise::Charge.retrieve("chrg_test_4yq7duw15p9hdrjp8oq")
|
6
6
|
end
|
7
7
|
|
@@ -17,6 +17,24 @@ class TestCharge < Minitest::Test
|
|
17
17
|
assert_equal "chrg_test_4yq7duw15p9hdrjp8oq", @charge.id
|
18
18
|
end
|
19
19
|
|
20
|
+
def test_that_unexpanded_resource_are_automatically_expanded
|
21
|
+
assert_instance_of Omise::Charge, @charge
|
22
|
+
assert_instance_of Omise::Customer, @charge.customer
|
23
|
+
assert_instance_of Omise::Transaction, @charge.transaction
|
24
|
+
assert_instance_of Omise::RefundList, @charge.refunds
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_that_we_can_retrieve_an_expanded_charge
|
28
|
+
charge = Omise::Charge.retrieve("chrg_test_4yq7duw15p9hdrjp8oq", expand: true)
|
29
|
+
|
30
|
+
assert_instance_of Omise::Charge, charge
|
31
|
+
assert_equal "chrg_test_4yq7duw15p9hdrjp8oq", @charge.id
|
32
|
+
|
33
|
+
assert_instance_of Omise::Customer, @charge.customer
|
34
|
+
assert_instance_of Omise::Transaction, @charge.transaction
|
35
|
+
assert_instance_of Omise::RefundList, @charge.refunds
|
36
|
+
end
|
37
|
+
|
20
38
|
def test_that_we_can_list_all_charge
|
21
39
|
charges = Omise::Charge.list
|
22
40
|
|
@@ -53,4 +71,30 @@ class TestCharge < Minitest::Test
|
|
53
71
|
def test_that_we_can_retrieve_a_list_of_refunds
|
54
72
|
assert_instance_of Omise::RefundList, @charge.refunds
|
55
73
|
end
|
74
|
+
|
75
|
+
def test_that_paid_return_the_value_of_captured
|
76
|
+
captured_charge = Omise::Charge.new(JSON.load('{ "captured": true }'))
|
77
|
+
uncaptured_charge = Omise::Charge.new(JSON.load('{ "captured": false }'))
|
78
|
+
|
79
|
+
assert_instance_of TrueClass, captured_charge.captured
|
80
|
+
assert_instance_of TrueClass, captured_charge.paid
|
81
|
+
|
82
|
+
assert_instance_of FalseClass, uncaptured_charge.captured
|
83
|
+
assert_instance_of FalseClass, uncaptured_charge.paid
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_that_captured_return_the_value_of_paid
|
87
|
+
paid_charge = Omise::Charge.new(JSON.load('{ "paid": true }'))
|
88
|
+
unpaid_charge = Omise::Charge.new(JSON.load('{ "paid": false }'))
|
89
|
+
|
90
|
+
assert_instance_of TrueClass, paid_charge.paid
|
91
|
+
assert_instance_of TrueClass, paid_charge.captured
|
92
|
+
|
93
|
+
assert_instance_of FalseClass, unpaid_charge.paid
|
94
|
+
assert_instance_of FalseClass, unpaid_charge.captured
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_that_we_can_send_a_capture_request
|
98
|
+
assert @charge.capture
|
99
|
+
end
|
56
100
|
end
|
data/test/omise/test_customer.rb
CHANGED
data/test/omise/test_dispute.rb
CHANGED
data/test/omise/test_refund.rb
CHANGED
@@ -0,0 +1,36 @@
|
|
1
|
+
require "support"
|
2
|
+
|
3
|
+
class TestResource < Omise::Test
|
4
|
+
def test_we_can_initialize_a_resource
|
5
|
+
resource = Omise::Resource.new(Omise.api_url, "/", "skey_xxx")
|
6
|
+
|
7
|
+
assert_instance_of Omise::Resource, resource
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_that_the_version_header_is_not_set_if_the_version_config_is_not_set
|
11
|
+
resource = Omise::Resource.new(Omise.api_url, "/", "skey_xxx")
|
12
|
+
|
13
|
+
assert_instance_of Hash, resource.headers
|
14
|
+
assert_nil resource.headers[:omise_version]
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_that_the_version_header_is_set_if_the_version_config_is_set
|
18
|
+
Omise.api_version = "2014-07-27"
|
19
|
+
resource = Omise::Resource.new(Omise.api_url, "/", "skey_xxx")
|
20
|
+
|
21
|
+
assert_instance_of Hash, resource.headers
|
22
|
+
assert_equal "2014-07-27", resource.headers[:omise_version]
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_that_the_path_is_set
|
26
|
+
resource = Omise::Resource.new(Omise.api_url, "/charges", "skey_xxx")
|
27
|
+
|
28
|
+
assert_equal "https://api.omise.co/charges", resource.uri
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_that_the_key_is_set
|
32
|
+
resource = Omise::Resource.new(Omise.api_url, "/charges", "skey_xxx")
|
33
|
+
|
34
|
+
assert_equal "skey_xxx", resource.key
|
35
|
+
end
|
36
|
+
end
|
data/test/omise/test_token.rb
CHANGED
data/test/omise/test_transfer.rb
CHANGED
data/test/support.rb
CHANGED
@@ -3,10 +3,26 @@ require "bundler/setup"
|
|
3
3
|
|
4
4
|
Bundler.require(:default, :test)
|
5
5
|
|
6
|
-
|
6
|
+
require "minitest/autorun"
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
module Omise
|
9
|
+
class Test < Minitest::Test
|
10
|
+
def before_setup
|
11
|
+
Omise.test!
|
12
|
+
Omise.api_key = "pkey_test_4yq6tct0llin5nyyi5l"
|
13
|
+
Omise.vault_key = "skey_test_4yq6tct0lblmed2yp5t"
|
14
|
+
Omise.api_version = nil
|
15
|
+
end
|
11
16
|
|
12
|
-
|
17
|
+
def setup
|
18
|
+
before_setup
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.setup(&block)
|
22
|
+
define_method :setup do
|
23
|
+
before_setup
|
24
|
+
instance_exec(&block)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omise
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robin Clart
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -127,8 +127,10 @@ files:
|
|
127
127
|
- test/fixtures/api.omise.co/charges-get.json
|
128
128
|
- test/fixtures/api.omise.co/charges-post.json
|
129
129
|
- test/fixtures/api.omise.co/charges/404-get.json
|
130
|
+
- test/fixtures/api.omise.co/charges/chrg_test_4yq7duw15p9hdrjp8oq-get-expand-true.json
|
130
131
|
- test/fixtures/api.omise.co/charges/chrg_test_4yq7duw15p9hdrjp8oq-get.json
|
131
132
|
- test/fixtures/api.omise.co/charges/chrg_test_4yq7duw15p9hdrjp8oq-patch.json
|
133
|
+
- test/fixtures/api.omise.co/charges/chrg_test_4yq7duw15p9hdrjp8oq/capture-post.json
|
132
134
|
- test/fixtures/api.omise.co/charges/chrg_test_4yq7duw15p9hdrjp8oq/refunds-get.json
|
133
135
|
- test/fixtures/api.omise.co/charges/chrg_test_4yq7duw15p9hdrjp8oq/refunds-post.json
|
134
136
|
- test/fixtures/api.omise.co/charges/chrg_test_4yq7duw15p9hdrjp8oq/refunds/404-get.json
|
@@ -173,6 +175,7 @@ files:
|
|
173
175
|
- test/omise/test_dispute.rb
|
174
176
|
- test/omise/test_recipient.rb
|
175
177
|
- test/omise/test_refund.rb
|
178
|
+
- test/omise/test_resource.rb
|
176
179
|
- test/omise/test_token.rb
|
177
180
|
- test/omise/test_transaction.rb
|
178
181
|
- test/omise/test_transfer.rb
|
@@ -207,8 +210,10 @@ test_files:
|
|
207
210
|
- test/fixtures/api.omise.co/charges-get.json
|
208
211
|
- test/fixtures/api.omise.co/charges-post.json
|
209
212
|
- test/fixtures/api.omise.co/charges/404-get.json
|
213
|
+
- test/fixtures/api.omise.co/charges/chrg_test_4yq7duw15p9hdrjp8oq-get-expand-true.json
|
210
214
|
- test/fixtures/api.omise.co/charges/chrg_test_4yq7duw15p9hdrjp8oq-get.json
|
211
215
|
- test/fixtures/api.omise.co/charges/chrg_test_4yq7duw15p9hdrjp8oq-patch.json
|
216
|
+
- test/fixtures/api.omise.co/charges/chrg_test_4yq7duw15p9hdrjp8oq/capture-post.json
|
212
217
|
- test/fixtures/api.omise.co/charges/chrg_test_4yq7duw15p9hdrjp8oq/refunds-get.json
|
213
218
|
- test/fixtures/api.omise.co/charges/chrg_test_4yq7duw15p9hdrjp8oq/refunds-post.json
|
214
219
|
- test/fixtures/api.omise.co/charges/chrg_test_4yq7duw15p9hdrjp8oq/refunds/404-get.json
|
@@ -253,7 +258,9 @@ test_files:
|
|
253
258
|
- test/omise/test_dispute.rb
|
254
259
|
- test/omise/test_recipient.rb
|
255
260
|
- test/omise/test_refund.rb
|
261
|
+
- test/omise/test_resource.rb
|
256
262
|
- test/omise/test_token.rb
|
257
263
|
- test/omise/test_transaction.rb
|
258
264
|
- test/omise/test_transfer.rb
|
259
265
|
- test/support.rb
|
266
|
+
has_rdoc:
|