xfers 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 35b472a1dbed8803adec5ac5366ddfd4356965e9
4
+ data.tar.gz: db0e07a6c28b63d6d6349b353224fac335b492e5
5
+ SHA512:
6
+ metadata.gz: 2cc5b660e7e126efccdb9c7642ae8254f8167cebf299f10368231fa287382dd61b6c89464d14440e106d487c40c95981f6e2a1649ac0cb6ff7d383d9c5fa9a17
7
+ data.tar.gz: 41c503d906ad7eb16447a96f1433b70bb13d56a1ed6a3c33e4bc0bdb9e455e955dacc9e9fe927e2b18d3bff5f74a01092a9a15e58b27179dd2175eb2cc671b46
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ /Gemfile.lock
2
+ .rvmrc
3
+ Gemfile.lock
4
+ tags
5
+ .idea
6
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ gem 'bundler'
7
+ gem 'rest-client'
8
+ end
data/README.md ADDED
@@ -0,0 +1,72 @@
1
+ # Xfers Ruby Bindings
2
+
3
+ You can sign up for a Xfers account at https://xfers.com.
4
+
5
+ ## Installation
6
+
7
+ You don't need this source code unless you want to modify the gem. If you just
8
+ want to use the Xfers Ruby bindings, you should run:
9
+
10
+ gem install xfers
11
+
12
+ If you want to build the gem from source:
13
+
14
+ gem build xfers.gemspec
15
+
16
+ ### Requirements
17
+
18
+ * Ruby 2.0.0 or above.
19
+ * rest-client
20
+
21
+ ### Bundler
22
+
23
+ If you are installing via bundler, you should be sure to use the https rubygems
24
+ source in your Gemfile, as any gems fetched over http could potentially be
25
+ compromised in transit and alter the code of gems fetched securely over https:
26
+
27
+ ``` ruby
28
+ source 'https://rubygems.org'
29
+
30
+ gem 'xfers'
31
+ ```
32
+
33
+ ## Usage
34
+
35
+ The library needs to be configured with your account's secret key which is
36
+ available in the [Dashboard][dashboard]. Assign its value to `Xfers.api_key`
37
+ and the library will send it along automatically with every request:
38
+
39
+ ``` ruby
40
+ require "xfers"
41
+ Xfers.set_api_key 'G-zsfAEScrqdU8GhWTEdjfdnb3XRdU8q1fH-nuWfSzo'
42
+ Xfers.set_sg_sandbox
43
+
44
+ # Retrieve user information
45
+ begin
46
+ resp = Xfers::User.retrieve
47
+ puts resp[:first_name]
48
+ puts resp[:last_name]
49
+ puts resp[:available_balance]
50
+ puts resp
51
+ rescue Xfers::XfersError => e
52
+ puts e.to_s
53
+ end
54
+
55
+ # Creating a charge
56
+ begin
57
+ Xfers::Charge.create(
58
+ :amount => '19.99',
59
+ :currency => 'SGD',
60
+ :order_id => 'A00834',
61
+ :description => 'Carousell user - Konsolidate'
62
+ )
63
+ rescue Xfers::XfersError => e
64
+ puts e.to_s
65
+ end
66
+
67
+ ```
68
+
69
+
70
+ ## Documentation
71
+
72
+ Please see http://docs.xfers.io/ for up-to-date documentation.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,83 @@
1
+ require 'xfers'
2
+
3
+ Xfers.set_api_key 'G-zsfAEScrqdU8GhWTEdjfdnb3XRdU8q1fH-nuWfSzo'
4
+ Xfers.set_sg_sandbox
5
+
6
+ begin
7
+ puts 'Adding bank account...'
8
+ params = {
9
+ 'account_no'=> '12988012511',
10
+ 'bank'=> 'OCBC'
11
+ }
12
+ bank_accounts = Xfers::BankAccount.add params
13
+ puts "number of bank accounts=> #{bank_accounts.length}"
14
+ bank_accounts.each { |account| puts "Bank Account=> #{account}" }
15
+ rescue Xfers::XfersError => e
16
+ puts e.to_s
17
+ end
18
+
19
+ begin
20
+ puts 'Adding bank account...'
21
+ params = {
22
+ 'account_no'=> '03931234321',
23
+ 'bank'=> 'DBS'
24
+ }
25
+ bank_accounts = Xfers::BankAccount.add params
26
+ puts "number of bank accounts=> #{bank_accounts.length}"
27
+ bank_accounts.each { |account| puts "Bank Account=> #{account}" }
28
+ rescue Xfers::XfersError => e
29
+ puts e.to_s
30
+ end
31
+
32
+ begin
33
+ puts 'Listing all bank accounts...'
34
+ bank_accounts = Xfers::BankAccount.list_all
35
+ puts "number of bank accounts=> #{bank_accounts.length}"
36
+ bank_accounts.each { |account| puts "Bank Account=> #{account}" }
37
+ rescue Xfers::XfersError => e
38
+ puts e.to_s
39
+ end
40
+
41
+
42
+ begin
43
+ puts 'Deleting bank account...'
44
+ resp = Xfers::BankAccount.delete '21'
45
+ puts resp
46
+ rescue Xfers::XfersError => e
47
+ puts e.to_s
48
+ end
49
+
50
+ begin
51
+ params = {
52
+ 'account_no'=> '209367835',
53
+ 'bank'=> 'POSB'
54
+ }
55
+ puts 'Updating bank account...'
56
+ resp = Xfers::BankAccount.update '22', params
57
+ puts resp
58
+ rescue Xfers::XfersError => e
59
+ puts e.to_s
60
+ end
61
+
62
+ begin
63
+ puts 'Withdrawing from bank account...'
64
+ params = {
65
+ 'amount'=> '20',
66
+ 'express'=> 'false'
67
+ }
68
+ resp = Xfers::BankAccount.withdraw '22', params
69
+ puts resp
70
+ rescue Xfers::XfersError => e
71
+ puts e.to_s
72
+ end
73
+
74
+ begin
75
+ puts 'Listing withdrawal requests...'
76
+ params = {
77
+ 'filter'=> 'pending'
78
+ }
79
+ withdrawal_requests = Xfers::BankAccount.withdrawal_requests params
80
+ withdrawal_requests.each { |req| puts "Withdrawal request=> #{req}" }
81
+ rescue Xfers::XfersError => e
82
+ puts e.to_s
83
+ end
@@ -0,0 +1,82 @@
1
+ require 'xfers'
2
+
3
+ Xfers.set_api_key 'G-zsfAEScrqdU8GhWTEdjfdnb3XRdU8q1fH-nuWfSzo'
4
+ Xfers.set_sg_sandbox
5
+
6
+ charge_id = ''
7
+
8
+ begin
9
+ puts 'Listing all charges...'
10
+ params = {
11
+ 'limit'=> '5'
12
+ }
13
+ charges = Xfers::Charge.list_all params
14
+ charges.each { |charge|
15
+ puts charge
16
+ }
17
+ rescue Xfers::XfersError => e
18
+ puts e.to_s
19
+ end
20
+
21
+ begin
22
+ puts 'Creating charge...'
23
+ params = {
24
+ 'amount'=> '1.99',
25
+ 'currency'=> 'SGD',
26
+ 'order_id'=> 'A01231z2',
27
+ 'description'=> 'Carousell user - Konsolidate'
28
+ }
29
+ resp = Xfers::Charge.create params
30
+ charge_id = resp[:id]
31
+ puts resp
32
+ rescue Xfers::XfersError => e
33
+ puts e.to_s
34
+ end
35
+
36
+ begin
37
+ puts "Retrieving charge... #{charge_id}"
38
+ resp = Xfers::Charge.retrieve charge_id
39
+ puts resp
40
+ rescue Xfers::XfersError => e
41
+ puts e.to_s
42
+ end
43
+
44
+ begin
45
+ params = {
46
+ 'currency'=> 'SGD',
47
+ 'order_id'=> 'A01231z2',
48
+ 'total_amount'=> '1.99',
49
+ 'status'=> 'unclaimed'
50
+ }
51
+ puts "Validating charge... #{charge_id}"
52
+ resp = Xfers::Charge.validate charge_id, params
53
+ puts resp
54
+ rescue Xfers::XfersError => e
55
+ puts e.to_s
56
+ end
57
+
58
+ begin
59
+ puts "Cancelling charge... #{charge_id}"
60
+ resp = Xfers::Charge.cancel charge_id
61
+ puts resp
62
+ rescue Xfers::XfersError => e
63
+ puts e.to_s
64
+ end
65
+
66
+ begin
67
+ charge_id = 'your-charge-id'
68
+ puts "Settling charge... #{charge_id}"
69
+ resp = Xfers::Charge.settle charge_id, '512312'
70
+ puts resp
71
+ rescue Xfers::XfersError => e
72
+ puts e.to_s
73
+ end
74
+
75
+ begin
76
+ charge_id = 'your-charge-id'
77
+ puts "Refunding charge... #{charge_id}"
78
+ resp = Xfers::Charge.refund charge_id
79
+ puts resp
80
+ rescue Xfers::XfersError => e
81
+ puts e.to_s
82
+ end
@@ -0,0 +1,47 @@
1
+ require 'xfers'
2
+
3
+ Xfers.set_api_key 'G-zsfAEScrqdU8GhWTEdjfdnb3XRdU8q1fH-nuWfSzo'
4
+ Xfers.set_sg_sandbox
5
+ XFERS_APP_API_KEY = 'AeWpKz5cdPoJFUwF53sBee_WsSoqym_hspiX3bcoB_Y'
6
+
7
+ user_api_token = ''
8
+ begin
9
+ puts 'Authorizing connect...'
10
+ params = {
11
+ 'phone_no'=> '+6597288608',
12
+ 'signature'=> 'a4f001729fe3accdbb0d9cfaf3b49b0678a4c91b'
13
+ }
14
+ resp = Xfers::Connect.authorize params, XFERS_APP_API_KEY
15
+ puts resp
16
+ rescue Xfers::XfersError => e
17
+ puts e.to_s
18
+ end
19
+
20
+ begin
21
+ puts 'Getting connect token...'
22
+ params = {
23
+ 'otp'=> '870100',
24
+ 'phone_no'=> '+6597288608',
25
+ 'signature'=> '780acd13b239a8e3d4586662e6c1b1e750805b66',
26
+ 'return_url'=> 'https://mywebsite.com/api/v3/account_registration/completed'
27
+ }
28
+ resp = Xfers::Connect.get_token params, XFERS_APP_API_KEY
29
+ user_api_token = resp[:user_api_token]
30
+ puts resp
31
+ rescue Xfers::XfersError => e
32
+ puts e.to_s
33
+ end
34
+
35
+ begin
36
+ puts 'Retrieving user...'
37
+ Xfers.set_api_key user_api_token
38
+
39
+ resp = Xfers::User.retrieve
40
+ puts resp[:first_name]
41
+ puts resp[:last_name]
42
+ puts resp[:available_balance]
43
+ puts resp
44
+ rescue Xfers::XfersError => e
45
+ puts e.to_s
46
+ end
47
+
@@ -0,0 +1,40 @@
1
+ require 'xfers'
2
+
3
+ Xfers.set_api_key 'G-zsfAEScrqdU8GhWTEdjfdnb3XRdU8q1fH-nuWfSzo'
4
+ Xfers.set_sg_sandbox
5
+
6
+ intent_id = ''
7
+
8
+ begin
9
+ puts 'Creating intent...'
10
+ params = {
11
+ 'amount'=> '1.49',
12
+ 'currency'=> 'SGD',
13
+ 'bank'=> 'DBS',
14
+ 'request_id'=> 'YOUR-CUSTOM-ID',
15
+ 'notify_url'=> 'https://mysite.com/topup_notification'
16
+ }
17
+ resp = Xfers::Intent.create params
18
+ intent_id = resp[:id]
19
+ puts resp
20
+ rescue Xfers::XfersError => e
21
+ puts e.to_s
22
+ end
23
+
24
+ begin
25
+ puts 'Listing all intents...'
26
+ intents = Xfers::Intent.list_all
27
+ intents.each { |intent|
28
+ puts intent
29
+ }
30
+ rescue Xfers::XfersError => e
31
+ puts e.to_s
32
+ end
33
+
34
+ begin
35
+ puts 'Cancelling intent...'
36
+ resp = Xfers::Intent.cancel intent_id
37
+ puts resp
38
+ rescue Xfers::XfersError => e
39
+ puts e.to_s
40
+ end
@@ -0,0 +1,43 @@
1
+ require 'xfers'
2
+
3
+ Xfers.set_api_key 'G-zsfAEScrqdU8GhWTEdjfdnb3XRdU8q1fH-nuWfSzo'
4
+ Xfers.set_sg_sandbox
5
+
6
+ payout_id = ''
7
+
8
+ begin
9
+ puts 'Creating payout...'
10
+ params = {
11
+ 'amount'=> '0.84',
12
+ 'invoice_id'=> 'SPA-MEMBERSHIP',
13
+ 'recipient'=> 'demo@xfers.io'
14
+ }
15
+ resp = Xfers::Payout.create params
16
+ payout_id = resp[:id]
17
+ puts resp[:recipient]
18
+ puts resp[:invoice_id]
19
+ puts resp
20
+ rescue Xfers::XfersError => e
21
+ puts e.to_s
22
+ end
23
+
24
+ begin
25
+ puts 'Retrieving payout...'
26
+ resp = Xfers::Payout.retrieve payout_id
27
+ puts resp
28
+ rescue Xfers::XfersError => e
29
+ puts e.to_s
30
+ end
31
+
32
+ begin
33
+ puts 'Listing all payouts...'
34
+ params = {
35
+ 'recipient'=> '+6597288608'
36
+ }
37
+ payouts = Xfers::Payout.list_all params
38
+ payouts.each { |payout|
39
+ puts payout
40
+ }
41
+ rescue Xfers::XfersError => e
42
+ puts e.to_s
43
+ end
@@ -0,0 +1,60 @@
1
+ require 'xfers'
2
+
3
+ Xfers.set_api_key 'G-zsfAEScrqdU8GhWTEdjfdnb3XRdU8q1fH-nuWfSzo'
4
+ Xfers.set_sg_sandbox
5
+
6
+ begin
7
+ puts 'Retrieving user...'
8
+ resp = Xfers::User.retrieve
9
+ puts resp[:first_name]
10
+ puts resp[:last_name]
11
+ puts resp[:available_balance]
12
+ puts resp
13
+ rescue Xfers::XfersError => e
14
+ puts e.to_s
15
+ end
16
+
17
+ begin
18
+ puts 'Updating user...'
19
+ params = {
20
+ 'first_name'=>'Tommy',
21
+ 'last_name'=>'Tan',
22
+ 'email'=>'jelly@xfers.io',
23
+ 'date_of_birth'=>'1986-02-27',
24
+ 'address_line_1'=>'Blk 608 Pasir Ris',
25
+ 'address_line_2'=>'#08-41',
26
+ 'nationality'=>'Singaporean',
27
+ 'postal_code'=>'510608',
28
+ 'identity_no'=>'S8692038G',
29
+ 'id_front_url'=>'http://angelsgateadvisory.sg/wp-content/uploads/2015/10/Logo.jpg',
30
+ 'id_back_url'=>'http://angelsgateadvisory.sg/wp-content/uploads/2015/10/Logo.jpg',
31
+ 'selfie_2id_url'=>'http://angelsgateadvisory.sg/wp-content/uploads/2015/10/Logo.jpg',
32
+ 'proof_of_address_url'=>'http://angelsgateadvisory.sg/wp-content/uploads/2015/10/Logo.jpg',
33
+ 'meta_data'=>'foobar'
34
+ }
35
+ resp = Xfers::User.update params
36
+ puts resp[:first_name]
37
+ puts resp[:last_name]
38
+ puts resp[:available_balance]
39
+ puts resp
40
+ rescue Xfers::XfersError => e
41
+ puts e.to_s
42
+ end
43
+
44
+ begin
45
+ puts 'Getting transfer info...'
46
+ resp = Xfers::User.transfer_info
47
+ puts resp
48
+ rescue Xfers::XfersError => e
49
+ puts e.to_s
50
+ end
51
+
52
+ begin
53
+ puts 'Getting activities...'
54
+ activities = Xfers::User.activities
55
+ activities.each { |activity|
56
+ puts activity
57
+ }
58
+ rescue Xfers::XfersError => e
59
+ puts e.to_s
60
+ end
@@ -0,0 +1,75 @@
1
+ module Xfers
2
+ module APIOperations
3
+
4
+ def self.create_auth_headers(connect_key)
5
+ connect_key.nil? ? {'X-XFERS-USER-API-KEY' => Xfers.get_api_key} : {'X-XFERS-APP-API-KEY' => connect_key}
6
+ end
7
+
8
+ def self.handle_api_error(msg, status_code)
9
+ case status_code
10
+ when 400
11
+ raise InvalidRequestError.new msg, status_code
12
+ when 401
13
+ raise AuthenticationError.new msg, status_code
14
+ when 500
15
+ raise InternalServerError.new msg, status_code
16
+ else
17
+ raise XfersError.new msg, status_code
18
+ end
19
+ end
20
+
21
+ def self.parse_and_symbolize(json_string)
22
+ parsed = JSON.parse(json_string)
23
+ begin
24
+ if parsed.kind_of?(Array)
25
+ arr = []
26
+ parsed.each { |item|
27
+ arr.push Hash[item.map{ |k, v| [k.to_sym, v] }]
28
+ }
29
+ arr
30
+ else
31
+ Hash[parsed.map{ |k, v| [k.to_sym, v] }]
32
+ end
33
+ rescue NoMethodError
34
+ parsed
35
+ end
36
+ end
37
+
38
+ def self.get(params={}, resource_url=nil, connect_key=nil)
39
+ RestClient::Request.execute(method: :get, url: "#{Xfers.get_api_base}#{resource_url}",
40
+ payload: params, headers: create_auth_headers(connect_key)) {
41
+ |r, request, result, &block|
42
+ handle_api_error(JSON.parse(r.body), r.code) if r.code != 200
43
+ parse_and_symbolize(r.body)
44
+ }
45
+ end
46
+
47
+ def self.post(params={}, resource_url=nil, connect_key=nil)
48
+ RestClient::Request.execute(method: :post, url: "#{Xfers.get_api_base}#{resource_url}",
49
+ payload: params, headers: create_auth_headers(connect_key)) {
50
+ |r, request, result, &block|
51
+ handle_api_error(JSON.parse(r.body), r.code) if r.code != 200
52
+ parse_and_symbolize(r.body)
53
+ }
54
+ end
55
+
56
+ def self.put(params={}, resource_url=nil, connect_key=nil)
57
+ RestClient::Request.execute(method: :put, url: "#{Xfers.get_api_base}#{resource_url}",
58
+ payload: params, headers: create_auth_headers(connect_key)) {
59
+ |r, request, result, &block|
60
+ handle_api_error(JSON.parse(r.body), r.code) if r.code != 200
61
+ parse_and_symbolize(r.body)
62
+ }
63
+ end
64
+
65
+ def self.delete(resource_url, connect_key=nil)
66
+ RestClient::Request.execute(method: :delete, url: "#{Xfers.get_api_base}#{resource_url}",
67
+ headers: create_auth_headers(connect_key)) {
68
+ |r, request, result, &block|
69
+ handle_api_error(JSON.parse(r.body), r.code) if r.code != 200
70
+ parse_and_symbolize(r.body)
71
+ }
72
+ end
73
+
74
+ end
75
+ end
@@ -0,0 +1,36 @@
1
+ module Xfers
2
+ module BankAccount
3
+ RESOUCE_URL = '/user/bank_account'
4
+
5
+
6
+ def self.list_all(connect_key=nil)
7
+ Xfers::APIOperations.get(nil, RESOUCE_URL, connect_key)
8
+ end
9
+
10
+ def self.add(params, connect_key=nil)
11
+ raise InvalidRequestError.new 'Params cannot be empty', 400 if params.nil? or params == ''
12
+ params['redirect'] = 'false'
13
+ Xfers::APIOperations.post params, RESOUCE_URL, connect_key
14
+ end
15
+
16
+ def self.update(bank_account_id, params, connect_key=nil)
17
+ raise InvalidRequestError.new 'BankAccount id cannot be empty', 400 if bank_account_id.nil? or bank_account_id == ''
18
+ Xfers::APIOperations.put params, "#{RESOUCE_URL}/#{bank_account_id}", connect_key
19
+ end
20
+
21
+ def self.delete(bank_account_id, connect_key=nil)
22
+ raise InvalidRequestError.new 'BankAccount id cannot be empty', 400 if bank_account_id.nil? or bank_account_id == ''
23
+ Xfers::APIOperations.delete "#{RESOUCE_URL}/#{bank_account_id}", connect_key
24
+ end
25
+
26
+ def self.withdraw(bank_account_id, params, connect_key=nil)
27
+ raise InvalidRequestError.new 'BankAccount id and params cannot be empty', 400 if bank_account_id.nil? or params.nil?
28
+ Xfers::APIOperations.post params, "#{RESOUCE_URL}/#{bank_account_id}/withdraw", connect_key
29
+ end
30
+
31
+ def self.withdrawal_requests(params=nil, connect_key=nil)
32
+ Xfers::APIOperations.get(params, "#{RESOUCE_URL}/withdrawal_requests", connect_key)[:withdrawal_requests]
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,44 @@
1
+ module Xfers
2
+ module Charge
3
+ RESOUCE_URL = '/charges'
4
+
5
+ def self.retrieve(charge_id, connect_key=nil)
6
+ raise InvalidRequestError.new 'Charge id cannot be empty', 400 if charge_id.nil? or charge_id == ''
7
+ Xfers::APIOperations.get nil, "#{RESOUCE_URL}/#{charge_id}", connect_key
8
+ end
9
+
10
+ def self.list_all(params=nil, connect_key=nil)
11
+ Xfers::APIOperations.get(params, RESOUCE_URL, connect_key)
12
+ end
13
+
14
+ def self.create(params, connect_key=nil)
15
+ raise InvalidRequestError.new 'Params cannot be empty', 400 if params.nil? or params == ''
16
+ params['redirect'] = 'false'
17
+ Xfers::APIOperations.post params, RESOUCE_URL, connect_key
18
+ end
19
+
20
+ def self.refund(charge_id, connect_key=nil)
21
+ raise InvalidRequestError.new 'Charge id cannot be empty', 400 if charge_id.nil? or charge_id == ''
22
+ Xfers::APIOperations.post nil, "#{RESOUCE_URL}/#{charge_id}/refunds", connect_key
23
+ end
24
+
25
+ def self.validate(charge_id, params, connect_key=nil)
26
+ raise InvalidRequestError.new 'Charge id cannot be empty', 400 if charge_id.nil? or charge_id == ''
27
+ Xfers::APIOperations.post params, "#{RESOUCE_URL}/#{charge_id}/validate", connect_key
28
+ end
29
+
30
+ def self.cancel(charge_id, connect_key=nil)
31
+ raise InvalidRequestError.new 'Charge id cannot be empty', 400 if charge_id.nil? or charge_id == ''
32
+ Xfers::APIOperations.post nil, "#{RESOUCE_URL}/#{charge_id}/cancel", connect_key
33
+ end
34
+
35
+ def self.settle(charge_id, settlement_code=nil, connect_key=nil)
36
+ raise InvalidRequestError.new 'Charge id cannot be empty', 400 if charge_id.nil? or charge_id == ''
37
+ params = nil
38
+ params = {'settlement_code'=> settlement_code} unless settlement_code.nil?
39
+
40
+ Xfers::APIOperations.post params, "#{RESOUCE_URL}/#{charge_id}", connect_key
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,16 @@
1
+ module Xfers
2
+ module Connect
3
+ RESOUCE_URL = '/authorize'
4
+
5
+ def self.authorize(params, connect_key=nil)
6
+ raise InvalidRequestError.new 'Params cannot be empty', 400 if params.nil? or params == ''
7
+ Xfers::APIOperations.post params, "#{RESOUCE_URL}/signup_login", connect_key
8
+ end
9
+
10
+ def self.get_token(params, connect_key=nil)
11
+ raise InvalidRequestError.new 'Params cannot be empty', 400 if params.nil? or params == ''
12
+ Xfers::APIOperations.get params, "#{RESOUCE_URL}/get_token", connect_key
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,4 @@
1
+ module Xfers
2
+ class AuthenticationError < XfersError
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Xfers
2
+ class InternalServerError < XfersError
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Xfers
2
+ class InvalidRequestError < XfersError
3
+ end
4
+ end
@@ -0,0 +1,17 @@
1
+ module Xfers
2
+ class XfersError < StandardError
3
+ attr_reader :message
4
+ attr_reader :http_status
5
+
6
+ def initialize(message=nil, http_status=nil)
7
+ @message = message
8
+ @http_status = http_status
9
+ end
10
+
11
+ def to_s
12
+ status_string = @http_status.nil? ? '' : "(Status #{@http_status}) "
13
+ "#{status_string}#{@message}"
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,20 @@
1
+ module Xfers
2
+ module Intent
3
+ RESOUCE_URL = '/intents'
4
+
5
+ def self.list_all(connect_key=nil)
6
+ Xfers::APIOperations.get(nil, RESOUCE_URL, connect_key)
7
+ end
8
+
9
+ def self.create(params, connect_key=nil)
10
+ raise InvalidRequestError.new 'Params cannot be empty', 400 if params.nil? or params == ''
11
+ Xfers::APIOperations.post params, RESOUCE_URL, connect_key
12
+ end
13
+
14
+ def self.cancel(intent_id, connect_key=nil)
15
+ raise InvalidRequestError.new 'Intent id cannot be empty', 400 if intent_id.nil? or intent_id == ''
16
+ Xfers::APIOperations.post nil, "#{RESOUCE_URL}/#{intent_id}/cancel", connect_key
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ module Xfers
2
+ module Payout
3
+ RESOUCE_URL = '/payouts'
4
+
5
+ def self.retrieve(payout_id, connect_key=nil)
6
+ raise InvalidRequestError.new 'Payout id cannot be empty', 400 if payout_id.nil? or payout_id == ''
7
+ Xfers::APIOperations.get nil, "#{RESOUCE_URL}/#{payout_id}", connect_key
8
+ end
9
+
10
+ def self.create(params, connect_key=nil)
11
+ raise InvalidRequestError.new 'Params cannot be empty', 400 if params.nil? or params == ''
12
+ Xfers::APIOperations.post params, RESOUCE_URL, connect_key
13
+ end
14
+
15
+ def self.list_all(params=nil, connect_key=nil)
16
+ Xfers::APIOperations.get(params, RESOUCE_URL, connect_key)
17
+ end
18
+
19
+ end
20
+ end
data/lib/xfers/user.rb ADDED
@@ -0,0 +1,23 @@
1
+ module Xfers
2
+ module User
3
+ RESOUCE_URL = '/user'
4
+
5
+ def self.retrieve(connect_key=nil)
6
+ Xfers::APIOperations.get nil, RESOUCE_URL, connect_key
7
+ end
8
+
9
+ def self.update(params, connect_key=nil)
10
+ raise InvalidRequestError.new 'Params cannot be empty', 400 if params.nil?
11
+ Xfers::APIOperations.put params, RESOUCE_URL, connect_key
12
+ end
13
+
14
+ def self.transfer_info(connect_key=nil)
15
+ Xfers::APIOperations.get nil, "#{RESOUCE_URL}/transfer_info", connect_key
16
+ end
17
+
18
+ def self.activities(connect_key=nil)
19
+ Xfers::APIOperations.get(nil, "#{RESOUCE_URL}/activities", connect_key)[:activities]
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ module Xfers
2
+ VERSION = '1.0.1'
3
+ end
data/lib/xfers.rb ADDED
@@ -0,0 +1,63 @@
1
+ require 'json'
2
+ require 'rest-client'
3
+
4
+ # Version
5
+ require 'xfers/version'
6
+
7
+ # API operations
8
+ require 'xfers/api_operations'
9
+
10
+ # Resources
11
+ require 'xfers/user'
12
+ require 'xfers/payout'
13
+ require 'xfers/intent'
14
+ require 'xfers/connect'
15
+ require 'xfers/charge'
16
+ require 'xfers/bank_account'
17
+
18
+
19
+ # Errors
20
+ require 'xfers/errors/xfers_error'
21
+ require 'xfers/errors/internal_server_error'
22
+ require 'xfers/errors/invalid_request_error'
23
+ require 'xfers/errors/authentication_error'
24
+
25
+ module Xfers
26
+
27
+ SG_SANDBOX_BASE = 'https://sandbox.xfers.io/api/v3'
28
+ SG_PRODUCTION_BASE = 'https://www.xfers.io/api/v3'
29
+ ID_SANDBOX_BASE = 'https://sandbox-id.xfers.com/api/v3'
30
+ ID_PRODUCTION_BASE = 'https://id.xfers.com/api/v3'
31
+
32
+ @@api_key = ''
33
+ @@api_base = ''
34
+
35
+ def self.set_sg_sandbox
36
+ @@api_base = SG_SANDBOX_BASE
37
+ end
38
+
39
+ def self.set_sg_production
40
+ @@api_base = SG_PRODUCTION_BASE
41
+ end
42
+
43
+ def self.set_id_sandbox
44
+ @@api_base = ID_SANDBOX_BASE
45
+ end
46
+
47
+ def self.set_id_production
48
+ @@api_base = ID_PRODUCTION_BASE
49
+ end
50
+
51
+ def self.set_api_key(api_key)
52
+ @@api_key = api_key
53
+ end
54
+
55
+ def self.get_api_key
56
+ @@api_key
57
+ end
58
+
59
+ def self.get_api_base
60
+ @@api_base
61
+ end
62
+
63
+ end
data/xfers.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ $:.unshift(File.join(File.dirname(__FILE__), 'lib'))
2
+
3
+ require 'xfers/version'
4
+
5
+ spec = Gem::Specification.new do |gem|
6
+ gem.name = 'xfers'
7
+ gem.version = Xfers::VERSION
8
+ gem.required_ruby_version = '>= 2.0.0'
9
+ gem.summary = 'Ruby bindings for the Xfers API'
10
+ gem.description = 'Xfers is the easiest way to accept payments online in South East Asia. See https://xfers.com for details.'
11
+ gem.author = 'Xfers'
12
+ gem.email = 'support@xfers.io'
13
+ gem.homepage = 'http://docs.xfers.io'
14
+ gem.license = 'MIT'
15
+
16
+ gem.add_runtime_dependency('rest-client', '~> 2.0')
17
+
18
+ gem.files = `git ls-files`.split("\n")
19
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ gem.require_paths = ['lib']
21
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: xfers
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Xfers
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-09-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ description: Xfers is the easiest way to accept payments online in South East Asia. See
28
+ https://xfers.com for details.
29
+ email: support@xfers.io
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - Gemfile
36
+ - README.md
37
+ - Rakefile
38
+ - examples/bank_account_example.rb
39
+ - examples/charges_example.rb
40
+ - examples/connect_example.rb
41
+ - examples/intents_example.rb
42
+ - examples/payouts_example.rb
43
+ - examples/user_example.rb
44
+ - lib/xfers.rb
45
+ - lib/xfers/api_operations.rb
46
+ - lib/xfers/bank_account.rb
47
+ - lib/xfers/charge.rb
48
+ - lib/xfers/connect.rb
49
+ - lib/xfers/errors/authentication_error.rb
50
+ - lib/xfers/errors/internal_server_error.rb
51
+ - lib/xfers/errors/invalid_request_error.rb
52
+ - lib/xfers/errors/xfers_error.rb
53
+ - lib/xfers/intent.rb
54
+ - lib/xfers/payout.rb
55
+ - lib/xfers/user.rb
56
+ - lib/xfers/version.rb
57
+ - xfers.gemspec
58
+ homepage: http://docs.xfers.io
59
+ licenses:
60
+ - MIT
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: 2.0.0
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.4.3
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: Ruby bindings for the Xfers API
82
+ test_files: []