omise 0.1.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.
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,39 @@
1
+ {
2
+ "object": "customer",
3
+ "id": "cust_test_4yq6txdpfadhbaqnwp3",
4
+ "livemode": false,
5
+ "location": "/customers/cust_test_4yq6txdpfadhbaqnwp3",
6
+ "default_card": "card_test_4yq6tuucl9h4erukfl0",
7
+ "email": "john.doe.the.second@example.com",
8
+ "description": "John Doe (id: 30)",
9
+ "created": "2015-01-15T04:03:52Z",
10
+ "cards": {
11
+ "object": "list",
12
+ "from": "1970-01-01T00:00:00+00:00",
13
+ "to": "2015-01-15T04:03:52+00:00",
14
+ "offset": 0,
15
+ "limit": 20,
16
+ "total": 1,
17
+ "data": [
18
+ {
19
+ "object": "card",
20
+ "id": "card_test_4yq6tuucl9h4erukfl0",
21
+ "livemode": false,
22
+ "location": "/customers/cust_test_4yq6txdpfadhbaqnwp3/cards/card_test_4yq6tuucl9h4erukfl0",
23
+ "country": "",
24
+ "city": "Bangkok",
25
+ "postal_code": "10320",
26
+ "financing": "",
27
+ "last_digits": "4242",
28
+ "brand": "Visa",
29
+ "expiration_month": 1,
30
+ "expiration_year": 2017,
31
+ "fingerprint": "sRF/oMw2UQJJp/WbU+2/ZbVzwROjpMf1lyhOHhOqziw=",
32
+ "name": "JOHN DOE",
33
+ "security_code_check": true,
34
+ "created": "2015-01-15T04:03:40Z"
35
+ }
36
+ ],
37
+ "location": "/customers/cust_test_4yq6txdpfadhbaqnwp3/cards"
38
+ }
39
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "object": "error",
3
+ "location": "https://docs.omise.co/api/errors#not-found",
4
+ "code": "not_found",
5
+ "message": "customer missing was not found"
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "object": "card",
3
+ "id": "card_test_4yq6tuucl9h4erukfl0",
4
+ "livemode": false,
5
+ "deleted": true
6
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "object": "card",
3
+ "id": "card_test_4yq6tuucl9h4erukfl0",
4
+ "livemode": false,
5
+ "location": "/customers/cust_test_4yq6txdpfadhbaqnwp3/cards/card_test_4yq6tuucl9h4erukfl0",
6
+ "country": "",
7
+ "city": "Bangkok",
8
+ "postal_code": "10320",
9
+ "financing": "",
10
+ "last_digits": "4242",
11
+ "brand": "Visa",
12
+ "expiration_month": 1,
13
+ "expiration_year": 2017,
14
+ "fingerprint": "sRF/oMw2UQJJp/WbU+2/ZbVzwROjpMf1lyhOHhOqziw=",
15
+ "name": "JOHN DOE",
16
+ "security_code_check": true,
17
+ "created": "2015-01-15T04:03:40Z"
18
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "object": "card",
3
+ "id": "card_test_4yq6tuucl9h4erukfl0",
4
+ "livemode": false,
5
+ "location": "/customers/cust_test_4yq6txdpfadhbaqnwp3/cards/card_test_4yq6tuucl9h4erukfl0",
6
+ "country": "",
7
+ "city": "Bangkok",
8
+ "postal_code": "10320",
9
+ "financing": "",
10
+ "last_digits": "4242",
11
+ "brand": "Visa",
12
+ "expiration_month": 1,
13
+ "expiration_year": 2017,
14
+ "fingerprint": "sRF/oMw2UQJJp/WbU+2/ZbVzwROjpMf1lyhOHhOqziw=",
15
+ "name": "JOHN W. DOE",
16
+ "security_code_check": true,
17
+ "created": "2015-01-15T04:03:40Z"
18
+ }
@@ -0,0 +1,26 @@
1
+ {
2
+ "object": "list",
3
+ "from": "1970-01-01T00:00:00+00:00",
4
+ "to": "2015-01-15T10:14:58+00:00",
5
+ "offset": 0,
6
+ "limit": 20,
7
+ "total": 2,
8
+ "data": [
9
+ {
10
+ "object": "transaction",
11
+ "id": "trxn_test_4yq7duwb9jts1vxgqua",
12
+ "type": "credit",
13
+ "amount": 96094,
14
+ "currency": "THB",
15
+ "created": "2015-01-15T05:00:29Z"
16
+ },
17
+ {
18
+ "object": "transaction",
19
+ "id": "trxn_test_4yqafnvlztbf3908vs1",
20
+ "type": "debit",
21
+ "amount": 192188,
22
+ "currency": "THB",
23
+ "created": "2015-01-15T10:12:25Z"
24
+ }
25
+ ]
26
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "object": "transaction",
3
+ "id": "trxn_test_4yq7duwb9jts1vxgqua",
4
+ "type": "credit",
5
+ "amount": 96094,
6
+ "currency": "THB",
7
+ "created": "2015-01-15T05:00:29Z"
8
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "object": "transaction",
3
+ "id": "trxn_test_4yqafnvlztbf3908vs1",
4
+ "type": "debit",
5
+ "amount": 192188,
6
+ "currency": "THB",
7
+ "created": "2015-01-15T10:12:25Z"
8
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "object": "transaction",
3
+ "id": "trxn_test_4yqmv79fzpy0gmz5mmq",
4
+ "type": "debit",
5
+ "amount": 10000,
6
+ "currency": "THB",
7
+ "created": "2015-01-16T07:23:45Z"
8
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "object": "list",
3
+ "from": "1970-01-01T00:00:00+00:00",
4
+ "to": "2015-01-15T10:16:08+00:00",
5
+ "offset": 0,
6
+ "limit": 20,
7
+ "total": 1,
8
+ "data": [
9
+ {
10
+ "object": "transfer",
11
+ "id": "trsf_test_4yqacz8t3cbipcj766u",
12
+ "livemode": false,
13
+ "location": "/transfers/trsf_test_4yqacz8t3cbipcj766u",
14
+ "sent": true,
15
+ "paid": true,
16
+ "amount": 192188,
17
+ "currency": "thb",
18
+ "failure_code": null,
19
+ "failure_message": null,
20
+ "transaction": "trxn_test_4yqafnvlztbf3908vs1",
21
+ "created": "2015-01-15T10:04:47Z"
22
+ }
23
+ ]
24
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "object": "transfer",
3
+ "id": "trsf_test_4yqacz8t3cbipcj766u",
4
+ "livemode": false,
5
+ "location": "/transfers/trsf_test_4yqacz8t3cbipcj766u",
6
+ "sent": true,
7
+ "paid": true,
8
+ "amount": 192188,
9
+ "currency": "thb",
10
+ "failure_code": null,
11
+ "failure_message": null,
12
+ "transaction": null,
13
+ "created": "2015-01-15T10:04:47Z"
14
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "object": "transfer",
3
+ "id": "trsf_test_4yqacz8t3cbipcj766u",
4
+ "livemode": false,
5
+ "location": "/transfers/trsf_test_4yqacz8t3cbipcj766u",
6
+ "sent": true,
7
+ "paid": true,
8
+ "amount": 192188,
9
+ "currency": "thb",
10
+ "failure_code": null,
11
+ "failure_message": null,
12
+ "transaction": "trxn_test_4yqafnvlztbf3908vs1",
13
+ "created": "2015-01-15T10:04:47Z"
14
+ }
@@ -0,0 +1,25 @@
1
+ {
2
+ "object": "token",
3
+ "id": "tokn_test_4yq8lbecl0q6dsjzxr5",
4
+ "livemode": false,
5
+ "location": "/tokens/tokn_test_4yq8lbecl0q6dsjzxr5",
6
+ "used": false,
7
+ "card": {
8
+ "object": "card",
9
+ "id": "card_test_4yq6tuucl9h4erukfl0",
10
+ "livemode": false,
11
+ "country": "",
12
+ "city": "Bangkok",
13
+ "postal_code": "10320",
14
+ "financing": "",
15
+ "last_digits": "4242",
16
+ "brand": "Visa",
17
+ "expiration_month": 1,
18
+ "expiration_year": 2017,
19
+ "fingerprint": "sRF/oMw2UQJJp/WbU+2/ZbVzwROjpMf1lyhOHhOqziw=",
20
+ "name": "JOHN DOE",
21
+ "security_code_check": true,
22
+ "created": "2015-01-15T04:03:40Z"
23
+ },
24
+ "created": "2015-01-15T07:03:56Z"
25
+ }
@@ -0,0 +1,25 @@
1
+ {
2
+ "object": "token",
3
+ "id": "tokn_test_4yq8lbecl0q6dsjzxr5",
4
+ "livemode": false,
5
+ "location": "/tokens/tokn_test_4yq8lbecl0q6dsjzxr5",
6
+ "used": false,
7
+ "card": {
8
+ "object": "card",
9
+ "id": "card_test_4yq6tuucl9h4erukfl0",
10
+ "livemode": false,
11
+ "country": "",
12
+ "city": "Bangkok",
13
+ "postal_code": "10320",
14
+ "financing": "",
15
+ "last_digits": "4242",
16
+ "brand": "Visa",
17
+ "expiration_month": 1,
18
+ "expiration_year": 2017,
19
+ "fingerprint": "sRF/oMw2UQJJp/WbU+2/ZbVzwROjpMf1lyhOHhOqziw=",
20
+ "name": "JOHN DOE",
21
+ "security_code_check": true,
22
+ "created": "2015-01-15T04:03:40Z"
23
+ },
24
+ "created": "2015-01-15T07:03:56Z"
25
+ }
@@ -0,0 +1,19 @@
1
+ require "support"
2
+
3
+ class TestAccount < Minitest::Test
4
+ def setup
5
+ @account = Omise::Account.retrieve
6
+ end
7
+
8
+ def test_that_we_can_retrieve_the_account
9
+ assert_instance_of Omise::Account, @account
10
+ assert_equal "/account", @account.location
11
+ end
12
+
13
+ def test_that_we_can_reload_a_customer
14
+ @account.attributes.taint
15
+ @account.reload
16
+
17
+ refute @account.attributes.tainted?
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require "support"
2
+
3
+ class TestBalance < Minitest::Test
4
+ def setup
5
+ @balance = Omise::Balance.retrieve
6
+ end
7
+
8
+ def test_that_we_can_retrieve_the_balance
9
+ assert_instance_of Omise::Balance, @balance
10
+ assert_equal "/balance", @balance.location
11
+ end
12
+
13
+ def test_that_we_can_reload_a_customer
14
+ @balance.attributes.taint
15
+ @balance.reload
16
+
17
+ refute @balance.attributes.tainted?
18
+ end
19
+ end
@@ -0,0 +1,52 @@
1
+ require "support"
2
+
3
+ class TestCard < Minitest::Test
4
+ def setup
5
+ @cards = Omise::Customer.retrieve("cust_test_4yq6txdpfadhbaqnwp3").cards
6
+ @card = @cards.retrieve("card_test_4yq6tuucl9h4erukfl0")
7
+ end
8
+
9
+ def test_that_we_can_retrieve_a_card
10
+ assert_instance_of Omise::Card, @card
11
+ assert_equal "card_test_4yq6tuucl9h4erukfl0", @card.id
12
+ end
13
+
14
+ def test_that_we_can_create_a_card
15
+ card = @cards.create({
16
+ name: "JOHN DOE",
17
+ number: "4242424242424242",
18
+ expiration_month: "1",
19
+ expiration_year: "2017",
20
+ security_code: "123"
21
+ })
22
+
23
+ assert_instance_of Omise::Card, card
24
+ assert_equal "card_test_4yq6tuucl9h4erukfl0", card.id
25
+ end
26
+
27
+ def test_that_a_card_can_be_reloaded
28
+ @card.attributes.taint
29
+ @card.reload
30
+
31
+ refute @card.attributes.tainted?
32
+ end
33
+
34
+ def test_that_retrieveing_a_non_existing_card_will_raise_an_error
35
+ assert_raises Omise::Error do
36
+ @cards.retrieve("404")
37
+ end
38
+ end
39
+
40
+ def test_that_a_card_can_be_updated
41
+ @card.update(name: "JOHN W. DOE")
42
+
43
+ assert_equal "JOHN W. DOE", @card.name
44
+ end
45
+
46
+ def test_that_a_card_can_be_destroyed
47
+ @card.destroy
48
+
49
+ assert @card.destroyed?
50
+ assert @card.deleted
51
+ end
52
+ end
@@ -0,0 +1,56 @@
1
+ require "support"
2
+
3
+ class TestCharge < Minitest::Test
4
+ def setup
5
+ @charge = Omise::Charge.retrieve("chrg_test_4yq7duw15p9hdrjp8oq")
6
+ end
7
+
8
+ def test_that_we_can_create_a_charge
9
+ charge = Omise::Charge.create
10
+
11
+ assert_instance_of Omise::Charge, charge
12
+ assert_equal "chrg_test_4yq7duw15p9hdrjp8oq", charge.id
13
+ end
14
+
15
+ def test_that_we_can_retrieve_a_charge
16
+ assert_instance_of Omise::Charge, @charge
17
+ assert_equal "chrg_test_4yq7duw15p9hdrjp8oq", @charge.id
18
+ end
19
+
20
+ def test_that_we_can_list_all_charge
21
+ charges = Omise::Charge.list
22
+
23
+ assert_instance_of Omise::List, charges
24
+ end
25
+
26
+ def test_that_we_can_update_a_charge
27
+ @charge.update(description: "Charge for order 3947 (XXL)")
28
+
29
+ assert_equal @charge.description, "Charge for order 3947 (XXL)"
30
+ end
31
+
32
+ def test_that_we_can_reload_a_charge
33
+ @charge.attributes.taint
34
+ @charge.reload
35
+
36
+ refute @charge.attributes.tainted?
37
+ end
38
+
39
+ def test_that_retrieveing_a_non_existing_charge_will_raise_an_error
40
+ assert_raises Omise::Error do
41
+ Omise::Charge.retrieve("404")
42
+ end
43
+ end
44
+
45
+ def test_that_a_customer_has_a_transaction
46
+ assert_instance_of Omise::Transaction, @charge.transaction
47
+ end
48
+
49
+ def test_that_a_customer_has_a_default_card
50
+ assert_instance_of Omise::Customer, @charge.customer
51
+ end
52
+
53
+ def test_that_we_can_retrieve_a_list_of_refunds
54
+ assert_instance_of Omise::RefundList, @charge.refunds
55
+ end
56
+ end
@@ -0,0 +1,59 @@
1
+ require "support"
2
+
3
+ class TestCustomer < Minitest::Test
4
+ def setup
5
+ @customer = Omise::Customer.retrieve("cust_test_4yq6txdpfadhbaqnwp3")
6
+ end
7
+
8
+ def test_that_we_can_create_a_customer
9
+ customer = Omise::Customer.create
10
+
11
+ assert_instance_of Omise::Customer, customer
12
+ assert_equal "cust_test_4yq6txdpfadhbaqnwp3", customer.id
13
+ end
14
+
15
+ def test_that_we_can_retrieve_a_customer
16
+ assert_instance_of Omise::Customer, @customer
17
+ assert_equal "cust_test_4yq6txdpfadhbaqnwp3", @customer.id
18
+ end
19
+
20
+ def test_that_we_can_list_all_customer
21
+ customers = Omise::Customer.list
22
+
23
+ assert_instance_of Omise::List, customers
24
+ end
25
+
26
+ def test_that_we_can_update_a_customer
27
+ @customer.update(email: "john.doe.the.second@example.com")
28
+
29
+ assert_equal @customer.email, "john.doe.the.second@example.com"
30
+ end
31
+
32
+ def test_that_we_can_destroy_a_customer
33
+ @customer.destroy
34
+
35
+ assert @customer.deleted
36
+ assert @customer.destroyed?
37
+ end
38
+
39
+ def test_that_we_can_reload_a_customer
40
+ @customer.attributes.taint
41
+ @customer.reload
42
+
43
+ refute @customer.attributes.tainted?
44
+ end
45
+
46
+ def test_that_retrieveing_a_non_existing_customer_will_raise_an_error
47
+ assert_raises Omise::Error do
48
+ Omise::Customer.retrieve("404")
49
+ end
50
+ end
51
+
52
+ def test_that_a_customer_has_a_list_of_card
53
+ assert_instance_of Omise::CardList, @customer.cards
54
+ end
55
+
56
+ def test_that_a_customer_has_a_default_card
57
+ assert_instance_of Omise::Card, @customer.default_card
58
+ end
59
+ end