xendit_api 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +116 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/xendit_api +9 -0
- data/lib/faraday_middleware/raise_http_exception.rb +59 -0
- data/lib/xendit_api/client.rb +185 -0
- data/lib/xendit_api/entities/bank.rb +14 -0
- data/lib/xendit_api/entities/base.rb +14 -0
- data/lib/xendit_api/entities/card_charge.rb +21 -0
- data/lib/xendit_api/entities/cash_account.rb +15 -0
- data/lib/xendit_api/entities/disbursement.rb +20 -0
- data/lib/xendit_api/entities/invoice.rb +30 -0
- data/lib/xendit_api/entities/virtual_account.rb +19 -0
- data/lib/xendit_api/error.rb +25 -0
- data/lib/xendit_api/version.rb +3 -0
- data/lib/xendit_api.rb +14 -0
- data/xendit_api.gemspec +35 -0
- metadata +208 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9f4a60e44e97ac8c8e3f299f7988a8e746b86cd7
|
4
|
+
data.tar.gz: 910e601f9a1516d56e7f188439e9fed32aeb37c4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 91b15811048589bc8cbc0cad9bb4746f1a28fd4339bbe247038d65d8059a58617d57c5dc2aa60babfcf8a9423b89c0778f953e81ddd12eb266bf361c86b49b27
|
7
|
+
data.tar.gz: 1a28da2f8673a7de68d2ffda776393946469179fd1ad9015dc8ce95a425ff744dc4dd8101ac6693a7fa21a049b1bd14b014d3785b3d3a2ea470e15ba268a3952
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Galih Muhammad
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
# XenditApi
|
2
|
+
|
3
|
+
A simple wrapper to interact with Xendit API.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'xendit_api'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install xendit_api
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
### Instantiating the client
|
24
|
+
require 'xendit_api'
|
25
|
+
|
26
|
+
client = XenditApi::Client.new(api_key: 'your_api_key')
|
27
|
+
|
28
|
+
### Get your cash balance
|
29
|
+
|
30
|
+
client.get_cash_balance
|
31
|
+
|
32
|
+
### Name Validator
|
33
|
+
This is to look up the name of an account holder for any bank account in Indonesia, the response is an empty hash if it is uncached. The 'true' response will be delivered via callback to the designed URL.
|
34
|
+
|
35
|
+
client.get_bank_account_data(account_number: '1234567899', bank_code: 'BCA')
|
36
|
+
|
37
|
+
### Get an invoice
|
38
|
+
To retrieve an existing invoice
|
39
|
+
|
40
|
+
client.get_invoice(id: '579c8d61f23fa4ca35e52da4')
|
41
|
+
|
42
|
+
### Create an invoice
|
43
|
+
Create invoice to accept bank transfers
|
44
|
+
|
45
|
+
client.create_invoice(
|
46
|
+
external_id: 'demo_1475801962607',
|
47
|
+
payer_email: 'sample_email@xendit.co',
|
48
|
+
description: 'Trip to Bali',
|
49
|
+
amount: 230000
|
50
|
+
)
|
51
|
+
|
52
|
+
### Get available banks for virtual_account
|
53
|
+
Retrieves the current list of banks Xendit support for creating virtual account.
|
54
|
+
|
55
|
+
client.get_banks_for_virtual_accounts
|
56
|
+
|
57
|
+
### Create A Fixed Virtual Account
|
58
|
+
Create a fixed virtual account to accept bank transfers, callback will be sent everytime this FVA is paid.
|
59
|
+
|
60
|
+
client.create_fixed_virtual_account(
|
61
|
+
external_id: 'demo_virtual_account_1475459775872',
|
62
|
+
bank_code: 'BCA',
|
63
|
+
name: 'Rika Sutanto',
|
64
|
+
virtual_account_number: nil
|
65
|
+
)
|
66
|
+
* Note that the virtual_account_number argument is optional
|
67
|
+
|
68
|
+
### Get available banks for disbursement
|
69
|
+
Retrieves the current list of banks Xendit support for disbursements.
|
70
|
+
|
71
|
+
client.get_banks_for_disbursement
|
72
|
+
|
73
|
+
### Get a disbursement
|
74
|
+
Retrieves the current status of a disbursement. This is often used for checking the status of a transaction.
|
75
|
+
|
76
|
+
client.get_disbursement(id: '57c9010f5ef9e7077bcb96b6')
|
77
|
+
|
78
|
+
### Create a disbursement
|
79
|
+
Create a disbursement order
|
80
|
+
|
81
|
+
client.create_disbursement(
|
82
|
+
idempotency_key: nil,
|
83
|
+
external_id: 'demo_1475459775872',
|
84
|
+
bank_code: 'BCA',
|
85
|
+
account_holder_name: 'Bob Jones',
|
86
|
+
account_number: '1231241231',
|
87
|
+
description: 'Reimbursement for shoes',
|
88
|
+
amount: 100000
|
89
|
+
)
|
90
|
+
|
91
|
+
* Note that the idempotency_key argument is optional
|
92
|
+
|
93
|
+
### Charge credit card
|
94
|
+
Charge a cedit card using token returned by xendit.js
|
95
|
+
|
96
|
+
client.charge_credit_card(
|
97
|
+
external_id: 'Xendit',
|
98
|
+
token: '586f0ba2ab70de5d2b409e0d',
|
99
|
+
amount: 100000
|
100
|
+
)
|
101
|
+
|
102
|
+
## Development
|
103
|
+
|
104
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
105
|
+
|
106
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
107
|
+
|
108
|
+
## Contributing
|
109
|
+
|
110
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/xendit_api.
|
111
|
+
|
112
|
+
|
113
|
+
## License
|
114
|
+
|
115
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
116
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "xendit_api"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/exe/xendit_api
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
#!/usr/exe/env ruby
|
2
|
+
# allow execution of the script using the command chmod +x exe/xendit_api (assuming you’re on Linux or OSX)
|
3
|
+
|
4
|
+
# This exe is isolated from the gem, so we need to manually require the file(s) that are going to be used
|
5
|
+
require_relative "../lib/xendit_api.rb"
|
6
|
+
require_relative "../lib/xendit_api/client"
|
7
|
+
|
8
|
+
balance = XenditApi::Client.new(api_key: 'xnd_development_OYGFfORw0LSql8JrLOAeTjKVYdGg94F+wSbj+R1q/WbS8LOiBAF2hQ==').get_cash_balance
|
9
|
+
puts balance
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
# @private
|
4
|
+
module FaradayMiddleware
|
5
|
+
# @private
|
6
|
+
class RaiseHttpException < Faraday::Middleware
|
7
|
+
def call(env)
|
8
|
+
@app.call(env).on_complete do |response|
|
9
|
+
case response[:status].to_i
|
10
|
+
when 400
|
11
|
+
raise XenditApi::BadRequest, error_message_400(response)
|
12
|
+
when 401
|
13
|
+
raise XenditApi::Unauthorized, error_message_400(response)
|
14
|
+
when 403
|
15
|
+
raise XenditApi::Forbidden, error_message_400(response)
|
16
|
+
when 404
|
17
|
+
raise XenditApi::NotFound, error_message_400(response)
|
18
|
+
when 500
|
19
|
+
raise XenditApi::InternalServerError, error_message_500(response, "Something is technically wrong.")
|
20
|
+
when 502
|
21
|
+
raise XenditApi::BadGateway, error_message_500(response, "The server returned an invalid or incomplete response.")
|
22
|
+
when 504
|
23
|
+
raise XenditApi::GatewayTimeout, error_message_500(response, "504 Gateway Time-out")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def initialize(app)
|
29
|
+
super app
|
30
|
+
@parser = nil
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def error_message_400(response)
|
36
|
+
"#{response[:method].to_s.upcase} #{response[:url].to_s}: #{response[:status]}#{error_body(response[:body])}"
|
37
|
+
end
|
38
|
+
|
39
|
+
def error_body(body)
|
40
|
+
# body gets passed as a string, not sure if it is passed as something else from other spots?
|
41
|
+
if not body.nil? and not body.empty? and body.kind_of?(String)
|
42
|
+
# removed multi_json thanks to wesnolte's commit
|
43
|
+
body = ::JSON.parse(body)
|
44
|
+
end
|
45
|
+
|
46
|
+
if body.nil?
|
47
|
+
nil
|
48
|
+
elsif body['meta'] and body['meta']['error_message'] and not body['meta']['error_message'].empty?
|
49
|
+
": #{body['meta']['error_message']}"
|
50
|
+
elsif body['error_message'] and not body['error_message'].empty?
|
51
|
+
": #{body['error_type']}: #{body['error_message']}"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def error_message_500(response, body=nil)
|
56
|
+
"#{response[:method].to_s.upcase} #{response[:url].to_s}: #{[response[:status].to_s + ':', body].compact.join(' ')}"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,185 @@
|
|
1
|
+
require "base64"
|
2
|
+
require "faraday"
|
3
|
+
require "faraday_middleware"
|
4
|
+
require "json"
|
5
|
+
|
6
|
+
module XenditApi
|
7
|
+
class Client
|
8
|
+
attr_reader :token
|
9
|
+
|
10
|
+
def initialize(api_key:)
|
11
|
+
@api_key = api_key
|
12
|
+
# Xendit requires us to use token in every request
|
13
|
+
# This is how to get the token, appending colon at the end then encode it
|
14
|
+
@token = Base64.strict_encode64(api_key + ':')
|
15
|
+
setup_connection
|
16
|
+
end
|
17
|
+
|
18
|
+
def get_cash_balance
|
19
|
+
return nil if @api_key.empty?
|
20
|
+
|
21
|
+
response = make_request('balance', 'get', {})
|
22
|
+
|
23
|
+
attrs = JSON.parse(response.body)
|
24
|
+
XenditApi::Entities::CashAccount.new(attrs)
|
25
|
+
end
|
26
|
+
|
27
|
+
def get_bank_account_data(account_number:, bank_code:)
|
28
|
+
return nil if @api_key.empty?
|
29
|
+
|
30
|
+
response = make_request(
|
31
|
+
'bank_account_data_requests',
|
32
|
+
'post',
|
33
|
+
{ bank_account_number: account_number, bank_code: bank_code }
|
34
|
+
)
|
35
|
+
|
36
|
+
JSON.parse(response.body)
|
37
|
+
end
|
38
|
+
|
39
|
+
def get_invoice(id:)
|
40
|
+
return nil if @api_key.empty?
|
41
|
+
|
42
|
+
path = 'v2/invoices/' + id.to_s
|
43
|
+
response = make_request(path, 'get')
|
44
|
+
|
45
|
+
attrs = JSON.parse(response.body)
|
46
|
+
XenditApi::Entities::Invoice.new(attrs)
|
47
|
+
end
|
48
|
+
|
49
|
+
def create_invoice(external_id:, payer_email:, description:, amount:)
|
50
|
+
return nil if @api_key.empty?
|
51
|
+
|
52
|
+
data = {
|
53
|
+
external_id: external_id,
|
54
|
+
payer_email: payer_email,
|
55
|
+
description: description,
|
56
|
+
amount: amount
|
57
|
+
}
|
58
|
+
|
59
|
+
response = make_request('v2/invoices', 'post', data)
|
60
|
+
|
61
|
+
attrs = JSON.parse(response.body)
|
62
|
+
XenditApi::Entities::Invoice.new(attrs)
|
63
|
+
end
|
64
|
+
|
65
|
+
def create_fixed_virtual_account(external_id:, bank_code:, name:, virtual_account_number:)
|
66
|
+
return nil if @api_key.empty?
|
67
|
+
|
68
|
+
data = {
|
69
|
+
external_id: external_id,
|
70
|
+
bank_code: bank_code,
|
71
|
+
name: name,
|
72
|
+
virtual_account_number: virtual_account_number
|
73
|
+
}
|
74
|
+
|
75
|
+
response = make_request('callback_virtual_accounts', 'post', data)
|
76
|
+
|
77
|
+
attrs = JSON.parse(response.body)
|
78
|
+
XenditApi::Entities::VirtualAccount.new(attrs)
|
79
|
+
end
|
80
|
+
|
81
|
+
def get_banks_for_virtual_account
|
82
|
+
return nil if @api_key.empty?
|
83
|
+
|
84
|
+
response = make_request(
|
85
|
+
'available_virtual_account_banks', 'get'
|
86
|
+
)
|
87
|
+
|
88
|
+
elements = JSON.parse(response.body)
|
89
|
+
banks = []
|
90
|
+
|
91
|
+
elements.each do |element|
|
92
|
+
banks << XenditApi::Entities::Bank.new(element)
|
93
|
+
end
|
94
|
+
|
95
|
+
banks
|
96
|
+
end
|
97
|
+
|
98
|
+
def get_banks_for_disbursement
|
99
|
+
return nil if @api_key.empty?
|
100
|
+
|
101
|
+
response = make_request(
|
102
|
+
'available_disbursements_banks', 'get'
|
103
|
+
)
|
104
|
+
|
105
|
+
elements = JSON.parse(response.body)
|
106
|
+
banks = []
|
107
|
+
|
108
|
+
elements.each do |element|
|
109
|
+
banks << XenditApi::Entities::Bank.new(element)
|
110
|
+
end
|
111
|
+
|
112
|
+
banks
|
113
|
+
end
|
114
|
+
|
115
|
+
def get_disbursement(id:)
|
116
|
+
return nil if @api_key.empty?
|
117
|
+
|
118
|
+
path = 'v2/disbursements/' + id.to_s
|
119
|
+
response = make_request(path, 'get')
|
120
|
+
|
121
|
+
attrs = JSON.parse(response.body)
|
122
|
+
XenditApi::Entities::Disbursement.new(attrs)
|
123
|
+
end
|
124
|
+
|
125
|
+
def create_disbursement(idempotency_key: nil, external_id:, bank_code:, account_holder_name:, account_number:, description:, amount:)
|
126
|
+
return nil if @api_key.empty?
|
127
|
+
|
128
|
+
data = {
|
129
|
+
external_id: external_id,
|
130
|
+
bank_code: bank_code,
|
131
|
+
account_holder_name: account_holder_name,
|
132
|
+
account_number: account_number,
|
133
|
+
description: description,
|
134
|
+
amount: amount
|
135
|
+
}
|
136
|
+
|
137
|
+
if idempotency_key.nil?
|
138
|
+
headers = {}
|
139
|
+
else
|
140
|
+
headers = { 'X-IDEMPOTENCY-KEY' => idempotency_key }
|
141
|
+
end
|
142
|
+
|
143
|
+
response = make_request('disbursements', 'post', data, headers)
|
144
|
+
|
145
|
+
attrs = JSON.parse(response.body)
|
146
|
+
XenditApi::Entities::Disbursement.new(attrs)
|
147
|
+
end
|
148
|
+
|
149
|
+
def charge_credit_card(external_id:, token:, amount:)
|
150
|
+
return nil if @api_key.empty?
|
151
|
+
|
152
|
+
data = {
|
153
|
+
external_id: external_id,
|
154
|
+
token: token,
|
155
|
+
amount: amount
|
156
|
+
}
|
157
|
+
|
158
|
+
response = make_request('credit_card_charges', 'post', data)
|
159
|
+
|
160
|
+
attrs = JSON.parse(response.body)
|
161
|
+
XenditApi::Entities::CardCharge.new(attrs)
|
162
|
+
end
|
163
|
+
|
164
|
+
private
|
165
|
+
|
166
|
+
def setup_connection
|
167
|
+
# start setting up connections
|
168
|
+
@connection = Faraday.new(url: XenditApi::BASE_URL) do |faraday|
|
169
|
+
faraday.response :logger # log requests to STDOUT
|
170
|
+
faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
|
171
|
+
faraday.use FaradayMiddleware::RaiseHttpException
|
172
|
+
end
|
173
|
+
|
174
|
+
@connection.authorization(:Basic, @token)
|
175
|
+
# finish setting up connection
|
176
|
+
end
|
177
|
+
|
178
|
+
def make_request(endpoint, method, payload = {}, headers = {})
|
179
|
+
# make the request for the transaction
|
180
|
+
return @connection.post(endpoint, payload, headers) if method == 'post'
|
181
|
+
|
182
|
+
@connection.get endpoint
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'model_attribute'
|
2
|
+
|
3
|
+
module XenditApi
|
4
|
+
module Entities
|
5
|
+
class Base
|
6
|
+
require "xendit_api/entities/bank.rb"
|
7
|
+
require "xendit_api/entities/card_charge.rb"
|
8
|
+
require "xendit_api/entities/cash_account.rb"
|
9
|
+
require "xendit_api/entities/disbursement.rb"
|
10
|
+
require "xendit_api/entities/invoice.rb"
|
11
|
+
require "xendit_api/entities/virtual_account.rb"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module XenditApi
|
2
|
+
module Entities
|
3
|
+
class CardCharge < Base
|
4
|
+
extend ModelAttribute
|
5
|
+
|
6
|
+
attribute :id, :string
|
7
|
+
attribute :external_id, :string
|
8
|
+
attribute :capture_amount, :integer
|
9
|
+
attribute :business_id, :string
|
10
|
+
attribute :merchant_reference_code, :string
|
11
|
+
attribute :merchant_id, :string
|
12
|
+
attribute :created, :string
|
13
|
+
attribute :status, :string
|
14
|
+
attribute :eci, :string
|
15
|
+
|
16
|
+
def initialize(attributes = {})
|
17
|
+
set_attributes(attributes)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module XenditApi
|
2
|
+
module Entities
|
3
|
+
class CashAccount < Base
|
4
|
+
extend ModelAttribute
|
5
|
+
|
6
|
+
attribute :balance, :integer
|
7
|
+
attribute :balance_cents, :integer
|
8
|
+
|
9
|
+
def initialize(attributes = {})
|
10
|
+
set_attributes(attributes, true)
|
11
|
+
@balance_cents = (balance.to_s + '00').to_i
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module XenditApi
|
2
|
+
module Entities
|
3
|
+
class Disbursement < Base
|
4
|
+
extend ModelAttribute
|
5
|
+
|
6
|
+
attribute :id, :string
|
7
|
+
attribute :user_id, :string
|
8
|
+
attribute :external_id, :string
|
9
|
+
attribute :amount, :integer
|
10
|
+
attribute :bank_code, :string
|
11
|
+
attribute :account_holder_name, :string
|
12
|
+
attribute :disbursement_description, :string
|
13
|
+
attribute :status, :string
|
14
|
+
|
15
|
+
def initialize(attributes = {})
|
16
|
+
set_attributes(attributes)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module XenditApi
|
2
|
+
module Entities
|
3
|
+
class Invoice < Base
|
4
|
+
extend ModelAttribute
|
5
|
+
|
6
|
+
attribute :id, :string
|
7
|
+
attribute :user_id, :string
|
8
|
+
attribute :external_id, :string
|
9
|
+
attribute :is_high, :boolean
|
10
|
+
attribute :status, :string
|
11
|
+
attribute :merchant_name, :string
|
12
|
+
attribute :amount, :integer
|
13
|
+
attribute :billable_amount, :integer
|
14
|
+
attribute :taxable_amount, :integer
|
15
|
+
attribute :received_amount, :integer
|
16
|
+
attribute :payer_email, :string
|
17
|
+
attribute :description, :string
|
18
|
+
attribute :invoice_url, :string
|
19
|
+
attribute :xendit_fee_amount, :integer
|
20
|
+
attribute :expiry_date, :string
|
21
|
+
attribute :taxes, :json
|
22
|
+
attribute :fees, :json
|
23
|
+
attribute :available_banks, :json
|
24
|
+
|
25
|
+
def initialize(attributes = {})
|
26
|
+
set_attributes(attributes)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module XenditApi
|
2
|
+
module Entities
|
3
|
+
class VirtualAccount < Base
|
4
|
+
extend ModelAttribute
|
5
|
+
|
6
|
+
attribute :id, :string
|
7
|
+
attribute :owner_id, :string
|
8
|
+
attribute :external_id, :string
|
9
|
+
attribute :bank_code, :string
|
10
|
+
attribute :merchant_code, :string
|
11
|
+
attribute :name, :string
|
12
|
+
attribute :account_number, :string
|
13
|
+
|
14
|
+
def initialize(attributes = {})
|
15
|
+
set_attributes(attributes)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module XenditApi
|
2
|
+
# Custom error class for rescuing from all Xendit API errors
|
3
|
+
class Error < StandardError; end
|
4
|
+
|
5
|
+
# Raised when Xendit API returns the HTTP status code 400
|
6
|
+
class BadRequest < Error; end
|
7
|
+
|
8
|
+
# Raised when Xendit API returns the HTTP status code 401
|
9
|
+
class Unauthorized < Error; end
|
10
|
+
|
11
|
+
# Raised when Xendit API returns the HTTP status code 403
|
12
|
+
class Forbidden < Error; end
|
13
|
+
|
14
|
+
# Raised when Xendit API returns the HTTP status code 404
|
15
|
+
class NotFound < Error; end
|
16
|
+
|
17
|
+
# Raised when Xendit API returns the HTTP status code 500
|
18
|
+
class InternalServerError < Error; end
|
19
|
+
|
20
|
+
# Raised when Xendit API returns the HTTP status code 502
|
21
|
+
class BadGateway < Error; end
|
22
|
+
|
23
|
+
# Raised when Xendit API returns the HTTP status code 504
|
24
|
+
class GatewayTimeout < Error; end
|
25
|
+
end
|
data/lib/xendit_api.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "xendit_api/version"
|
2
|
+
require "xendit_api/error"
|
3
|
+
require "xendit_api/entities/base"
|
4
|
+
require "faraday_middleware/raise_http_exception"
|
5
|
+
require "xendit_api/client"
|
6
|
+
|
7
|
+
module XenditApi
|
8
|
+
BASE_URL = 'https://api.xendit.co/'
|
9
|
+
BASE_VERSION = '0'
|
10
|
+
|
11
|
+
def self.base_url
|
12
|
+
@base_url = BASE_URL
|
13
|
+
end
|
14
|
+
end
|
data/xendit_api.gemspec
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'xendit_api/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "xendit_api"
|
8
|
+
spec.version = XenditApi::VERSION
|
9
|
+
spec.authors = ["Galih Muhammad"]
|
10
|
+
spec.email = ["galih0muhammad@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{A ruby wrapper for Xendit API}
|
13
|
+
spec.description = %q{Just simple and easy to use wrapper for Xendit API in ruby}
|
14
|
+
spec.homepage = "https://github.com/galliani/xendit_api"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_dependency 'model_attribute', '~> 3.0.0'
|
25
|
+
spec.add_dependency 'faraday', '~> 0.11.0'
|
26
|
+
spec.add_dependency 'faraday_middleware', '~> 0.10.1'
|
27
|
+
|
28
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
29
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
30
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
31
|
+
spec.add_development_dependency 'capybara', '2.5.0'
|
32
|
+
spec.add_development_dependency 'shoulda-context', '1.2.2'
|
33
|
+
spec.add_development_dependency 'shoulda-matchers', '3.1.1'
|
34
|
+
spec.add_development_dependency 'webmock', '2.1.0'
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,208 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: xendit_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Galih Muhammad
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-04-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: model_attribute
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.11.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.11.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: faraday_middleware
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.10.1
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.10.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.13'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.13'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: capybara
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 2.5.0
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 2.5.0
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: shoulda-context
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 1.2.2
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 1.2.2
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: shoulda-matchers
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 3.1.1
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 3.1.1
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: webmock
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - '='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 2.1.0
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - '='
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 2.1.0
|
153
|
+
description: Just simple and easy to use wrapper for Xendit API in ruby
|
154
|
+
email:
|
155
|
+
- galih0muhammad@gmail.com
|
156
|
+
executables:
|
157
|
+
- xendit_api
|
158
|
+
extensions: []
|
159
|
+
extra_rdoc_files: []
|
160
|
+
files:
|
161
|
+
- ".gitignore"
|
162
|
+
- ".rspec"
|
163
|
+
- ".travis.yml"
|
164
|
+
- Gemfile
|
165
|
+
- LICENSE.txt
|
166
|
+
- README.md
|
167
|
+
- Rakefile
|
168
|
+
- bin/console
|
169
|
+
- bin/setup
|
170
|
+
- exe/xendit_api
|
171
|
+
- lib/faraday_middleware/raise_http_exception.rb
|
172
|
+
- lib/xendit_api.rb
|
173
|
+
- lib/xendit_api/client.rb
|
174
|
+
- lib/xendit_api/entities/bank.rb
|
175
|
+
- lib/xendit_api/entities/base.rb
|
176
|
+
- lib/xendit_api/entities/card_charge.rb
|
177
|
+
- lib/xendit_api/entities/cash_account.rb
|
178
|
+
- lib/xendit_api/entities/disbursement.rb
|
179
|
+
- lib/xendit_api/entities/invoice.rb
|
180
|
+
- lib/xendit_api/entities/virtual_account.rb
|
181
|
+
- lib/xendit_api/error.rb
|
182
|
+
- lib/xendit_api/version.rb
|
183
|
+
- xendit_api.gemspec
|
184
|
+
homepage: https://github.com/galliani/xendit_api
|
185
|
+
licenses:
|
186
|
+
- MIT
|
187
|
+
metadata: {}
|
188
|
+
post_install_message:
|
189
|
+
rdoc_options: []
|
190
|
+
require_paths:
|
191
|
+
- lib
|
192
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
193
|
+
requirements:
|
194
|
+
- - ">="
|
195
|
+
- !ruby/object:Gem::Version
|
196
|
+
version: '0'
|
197
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - ">="
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: '0'
|
202
|
+
requirements: []
|
203
|
+
rubyforge_project:
|
204
|
+
rubygems_version: 2.5.1
|
205
|
+
signing_key:
|
206
|
+
specification_version: 4
|
207
|
+
summary: A ruby wrapper for Xendit API
|
208
|
+
test_files: []
|