wepay-api 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +21 -0
  3. data/.travis.yml +6 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +118 -0
  7. data/Rakefile +7 -0
  8. data/lib/wepay-api.rb +2 -0
  9. data/lib/wepay.rb +23 -0
  10. data/lib/wepay/api.rb +27 -0
  11. data/lib/wepay/api/account.rb +86 -0
  12. data/lib/wepay/api/base.rb +25 -0
  13. data/lib/wepay/api/checkout.rb +68 -0
  14. data/lib/wepay/api/preapproval.rb +50 -0
  15. data/lib/wepay/api/subscription.rb +50 -0
  16. data/lib/wepay/api/subscription_plan.rb +59 -0
  17. data/lib/wepay/api/withdrawal.rb +41 -0
  18. data/lib/wepay/client.rb +63 -0
  19. data/lib/wepay/client/data.rb +31 -0
  20. data/lib/wepay/client/token.rb +30 -0
  21. data/lib/wepay/configuration.rb +34 -0
  22. data/lib/wepay/error.rb +28 -0
  23. data/lib/wepay/middleware.rb +44 -0
  24. data/lib/wepay/oauth.rb +32 -0
  25. data/lib/wepay/version.rb +3 -0
  26. data/spec/fixtures/vcr_cassettes/Wepay_Middleware/Wepay_Middleware_CheckStatus/raises_a_Wepay_ApiError_with_proper_error_type_message_and_code.yml +35 -0
  27. data/spec/fixtures/vcr_cassettes/wepay_account.yml +38 -0
  28. data/spec/fixtures/vcr_cassettes/wepay_account_add_bank.yml +38 -0
  29. data/spec/fixtures/vcr_cassettes/wepay_account_balance.yml +38 -0
  30. data/spec/fixtures/vcr_cassettes/wepay_account_create.yml +46 -0
  31. data/spec/fixtures/vcr_cassettes/wepay_account_delete.yml +48 -0
  32. data/spec/fixtures/vcr_cassettes/wepay_account_find.yml +43 -0
  33. data/spec/fixtures/vcr_cassettes/wepay_account_get_tax.yml +38 -0
  34. data/spec/fixtures/vcr_cassettes/wepay_account_modify.yml +49 -0
  35. data/spec/fixtures/vcr_cassettes/wepay_account_set_tax.yml +38 -0
  36. data/spec/fixtures/vcr_cassettes/wepay_checkout.yml +40 -0
  37. data/spec/fixtures/vcr_cassettes/wepay_checkout_cancel.yml +38 -0
  38. data/spec/fixtures/vcr_cassettes/wepay_checkout_capture.yml +38 -0
  39. data/spec/fixtures/vcr_cassettes/wepay_checkout_create.yml +38 -0
  40. data/spec/fixtures/vcr_cassettes/wepay_checkout_find.yml +51 -0
  41. data/spec/fixtures/vcr_cassettes/wepay_checkout_modify.yml +40 -0
  42. data/spec/fixtures/vcr_cassettes/wepay_checkout_refund.yml +38 -0
  43. data/spec/fixtures/vcr_cassettes/wepay_preapproval.yml +39 -0
  44. data/spec/fixtures/vcr_cassettes/wepay_preapproval_cancel.yml +38 -0
  45. data/spec/fixtures/vcr_cassettes/wepay_preapproval_create.yml +38 -0
  46. data/spec/fixtures/vcr_cassettes/wepay_preapproval_find.yml +39 -0
  47. data/spec/fixtures/vcr_cassettes/wepay_preapproval_modify.yml +39 -0
  48. data/spec/fixtures/vcr_cassettes/wepay_subscription.yml +38 -0
  49. data/spec/fixtures/vcr_cassettes/wepay_subscription_cancel.yml +36 -0
  50. data/spec/fixtures/vcr_cassettes/wepay_subscription_create.yml +48 -0
  51. data/spec/fixtures/vcr_cassettes/wepay_subscription_find.yml +38 -0
  52. data/spec/fixtures/vcr_cassettes/wepay_subscription_modify.yml +38 -0
  53. data/spec/fixtures/vcr_cassettes/wepay_subscription_plan.yml +39 -0
  54. data/spec/fixtures/vcr_cassettes/wepay_subscription_plan_create.yml +48 -0
  55. data/spec/fixtures/vcr_cassettes/wepay_subscription_plan_delete.yml +48 -0
  56. data/spec/fixtures/vcr_cassettes/wepay_subscription_plan_find.yml +39 -0
  57. data/spec/fixtures/vcr_cassettes/wepay_subscription_plan_get_button.yml +48 -0
  58. data/spec/fixtures/vcr_cassettes/wepay_subscription_plan_modify.yml +49 -0
  59. data/spec/fixtures/vcr_cassettes/wepay_withdrawal.yml +38 -0
  60. data/spec/fixtures/vcr_cassettes/wepay_withdrawal_create.yml +38 -0
  61. data/spec/fixtures/vcr_cassettes/wepay_withdrawal_find.yml +38 -0
  62. data/spec/fixtures/vcr_cassettes/wepay_withdrawal_modify.yml +38 -0
  63. data/spec/settings.yml.example +6 -0
  64. data/spec/spec_helper.rb +12 -0
  65. data/spec/support/matchers.rb +5 -0
  66. data/spec/support/rspec_helper.rb +30 -0
  67. data/spec/support/settings.rb +14 -0
  68. data/spec/support/vcr.rb +17 -0
  69. data/spec/wepay/api/account_spec.rb +110 -0
  70. data/spec/wepay/api/checkout_spec.rb +86 -0
  71. data/spec/wepay/api/preapproval_spec.rb +69 -0
  72. data/spec/wepay/api/subscription_plan_spec.rb +83 -0
  73. data/spec/wepay/api/subscription_spec.rb +65 -0
  74. data/spec/wepay/api/withdrawal_spec.rb +53 -0
  75. data/spec/wepay/api_spec.rb +9 -0
  76. data/spec/wepay/configuration_spec.rb +25 -0
  77. data/spec/wepay/middleware_spec.rb +21 -0
  78. data/spec/wepay/oauth_spec.rb +23 -0
  79. data/wepay-api.gemspec +29 -0
  80. metadata +273 -0
@@ -0,0 +1,38 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://stage.wepayapi.com/v2/withdrawal/create
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"account_id":123456}'
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.8.8
12
+ Authorization:
13
+ - Bearer access_token
14
+ Content-Type:
15
+ - application/json
16
+ response:
17
+ status:
18
+ code: 200
19
+ message:
20
+ headers:
21
+ server:
22
+ - nginx
23
+ date:
24
+ - Mon, 16 Dec 2013 04:43:53 GMT
25
+ content-type:
26
+ - application/json
27
+ transfer-encoding:
28
+ - chunked
29
+ connection:
30
+ - close
31
+ strict-transport-security:
32
+ - max-age=2592000
33
+ body:
34
+ encoding: UTF-8
35
+ string: '{"withdrawal_id":123456789,"withdrawal_uri":"https:\/\/stage.wepay.com\/api\/withdrawal\/123456789\/f57129c710db1bfb69ce042c938cd0b9"}'
36
+ http_version:
37
+ recorded_at: Mon, 16 Dec 2013 04:43:54 GMT
38
+ recorded_with: VCR 2.8.0
@@ -0,0 +1,38 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://stage.wepayapi.com/v2/withdrawal/find
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"account_id":123456}'
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.8.8
12
+ Authorization:
13
+ - Bearer access_token
14
+ Content-Type:
15
+ - application/json
16
+ response:
17
+ status:
18
+ code: 200
19
+ message:
20
+ headers:
21
+ server:
22
+ - nginx
23
+ date:
24
+ - Mon, 16 Dec 2013 04:47:27 GMT
25
+ content-type:
26
+ - application/json
27
+ transfer-encoding:
28
+ - chunked
29
+ connection:
30
+ - close
31
+ strict-transport-security:
32
+ - max-age=2592000
33
+ body:
34
+ encoding: UTF-8
35
+ string: '[{"withdrawal_id":123456789,"state":"new","withdrawal_uri":"https:\/\/stage.wepay.com\/api\/withdrawal\/123456789\/f57129c710db1bfb69ce042c938cd0b9","callback_uri":null,"redirect_uri":"\/status\/withdrawal_complete\/123456789","create_time":1387169032,"capture_time":0,"recipient_name":"","recipient_confirmed":false,"type":"ach","amount":0,"note":"","account_id":123456}]'
36
+ http_version:
37
+ recorded_at: Mon, 16 Dec 2013 04:47:28 GMT
38
+ recorded_with: VCR 2.8.0
@@ -0,0 +1,38 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://stage.wepayapi.com/v2/withdrawal/modify
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"withdrawal_id":123456789,"callback_uri":"https://www.example.com/ipn/12345"}'
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.8.8
12
+ Authorization:
13
+ - Bearer access_token
14
+ Content-Type:
15
+ - application/json
16
+ response:
17
+ status:
18
+ code: 200
19
+ message:
20
+ headers:
21
+ server:
22
+ - nginx
23
+ date:
24
+ - Mon, 16 Dec 2013 04:49:36 GMT
25
+ content-type:
26
+ - application/json
27
+ transfer-encoding:
28
+ - chunked
29
+ connection:
30
+ - close
31
+ strict-transport-security:
32
+ - max-age=2592000
33
+ body:
34
+ encoding: UTF-8
35
+ string: '{"withdrawal_id":123456789,"state":"new","withdrawal_uri":"https:\/\/stage.wepay.com\/api\/withdrawal\/123456789\/f57129c710db1bfb69ce042c938cd0b9","callback_uri":"https:\/\/www.example.com\/ipn\/12345","redirect_uri":"\/status\/withdrawal_complete\/123456789","create_time":1387169032,"capture_time":0,"recipient_name":"","recipient_confirmed":false,"type":"ach","amount":0,"note":"","account_id":123456}'
36
+ http_version:
37
+ recorded_at: Mon, 16 Dec 2013 04:49:36 GMT
38
+ recorded_with: VCR 2.8.0
@@ -0,0 +1,6 @@
1
+ client_id: ...
2
+ client_secret: ...
3
+ access_token: access_token
4
+ account_id: 123456
5
+ scope: manage_accounts,view_balance,collect_payments,view_user,preapprove_payments,manage_subscriptions,send_money
6
+ using_stage: true
@@ -0,0 +1,12 @@
1
+ require 'bundler/setup'
2
+ require 'wepay-api'
3
+
4
+ Dir["./spec/support/**/*.rb"].each &method(:require)
5
+
6
+ RSpec.configure do |config|
7
+ config.treat_symbols_as_metadata_keys_with_true_values = true
8
+ config.expect_with(:rspec) {|c| c.syntax = :expect}
9
+ config.order = :random
10
+
11
+ config.include RspecHelper
12
+ end
@@ -0,0 +1,5 @@
1
+ RSpec::Matchers.define :have_keys do |*keys|
2
+ match do |object|
3
+ keys.all? { |key| object.key? key }
4
+ end
5
+ end
@@ -0,0 +1,30 @@
1
+ module RspecHelper
2
+ def self.included(base)
3
+ base.extend(ClassMethods)
4
+ end
5
+
6
+ module ClassMethods
7
+ ##
8
+ # Wraps a VCR cassette around API calls with the same name as the Wepay
9
+ # method called. For example, the cassette for `Wepay.checkout.create` will
10
+ # be called "Wepay.checkout.create". Because we repeat the same API calls
11
+ # in different examples, we can just reuse those VCR cassettes rather than
12
+ # recording new ones.
13
+ #
14
+ def record_api_methods
15
+ before do
16
+ stub_const("Wepay::Client::Data", Class.new(Wepay::Client::Data) do
17
+ def make_request(http_method, *args, &block)
18
+ VCR.use_cassette(['wepay', args[0].split('/')].flatten.join('.')) { super }
19
+ end
20
+ end)
21
+ end
22
+ end
23
+
24
+ def stub_api_requests
25
+ before do
26
+ Wepay::Client.any_instance.stub(:make_request)
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,14 @@
1
+ require "wepay-api"
2
+ require "yaml"
3
+ require "erb"
4
+
5
+ file_path = ["spec/settings.yml", "spec/settings.yml.example"].find &File.method(:exists?)
6
+ yaml = ERB.new(File.read(file_path)).result
7
+ settings = YAML.load(yaml)
8
+ SETTINGS = settings
9
+
10
+ Wepay.configure do |config|
11
+ SETTINGS.each do |name, value|
12
+ config.send(:"#{name}=", value) if config.respond_to?(:"#{name}=")
13
+ end
14
+ end
@@ -0,0 +1,17 @@
1
+ require "vcr"
2
+ require_relative "./settings"
3
+
4
+ VCR.configure do |config|
5
+ config.cassette_library_dir = "spec/fixtures/vcr_cassettes"
6
+ config.hook_into :faraday
7
+ config.default_cassette_options = {
8
+ record: :new_episodes
9
+ }
10
+ config.allow_http_connections_when_no_cassette = true
11
+
12
+ SETTINGS.each do |name, value|
13
+ config.filter_sensitive_data("<#{name.upcase}>") { value }
14
+ end
15
+
16
+ config.configure_rspec_metadata!
17
+ end
@@ -0,0 +1,110 @@
1
+ require "spec_helper"
2
+
3
+ describe Wepay::Api::Account do
4
+ let(:it) { described_class.new }
5
+ record_api_methods
6
+
7
+ describe "#show" do
8
+ it "shows the info of an account" do
9
+ data = it.show(
10
+ account_id: 123456,
11
+ access_token: 'access_token'
12
+ )
13
+
14
+ expect(data).to have_keys :account_id, :name, :state, :description, :account_uri, :payment_limit, :verification_state, :type, :create_time
15
+ end
16
+ end
17
+
18
+ describe "#find" do
19
+ it 'finds the accounts of the user associated with the access token' do
20
+ data = it.find(
21
+ access_token: 'access_token'
22
+ )
23
+
24
+ expect(data).to be_a Array
25
+ expect(data.first).to have_keys :account_id, :name, :state, :description, :account_uri, :payment_limit, :verification_state, :type, :create_time
26
+ end
27
+ end
28
+
29
+ describe "#create" do
30
+ it "creates an account" do
31
+ data = it.create(
32
+ name: "New Account",
33
+ description: "Created by API",
34
+ access_token: 'access_token'
35
+ )
36
+
37
+ expect(data).to have_keys :account_id, :account_uri
38
+ end
39
+ end
40
+
41
+ describe "#modify" do
42
+ it "modifies an account" do
43
+ data = it.modify(
44
+ account_id: "123456",
45
+ name: "New Account Name",
46
+ access_token: 'access_token'
47
+ )
48
+
49
+ expect(data).to have_keys :account_id, :name, :state, :description, :account_uri, :payment_limit, :verification_state, :type, :create_time
50
+ expect(data.name).to eq "New Account Name"
51
+ end
52
+ end
53
+
54
+ describe "#delete" do
55
+ it "deletes an account" do
56
+ data = it.delete(
57
+ account_id: "123456",
58
+ access_token: 'access_token'
59
+ )
60
+
61
+ expect(data).to have_keys :account_id, :state
62
+ expect(data.state).to eq "deleted"
63
+ end
64
+ end
65
+
66
+ describe "#balance" do
67
+ it "gets balance of an account" do
68
+ data = it.balance(
69
+ account_id: "123456",
70
+ access_token: 'access_token'
71
+ )
72
+
73
+ expect(data).to have_keys :pending_balance, :available_balance, :currency
74
+ end
75
+ end
76
+
77
+ describe "#add_bank" do
78
+ it "adds bank to an account" do
79
+ data = it.add_bank(
80
+ account_id: "123456",
81
+ access_token: 'access_token'
82
+ )
83
+
84
+ expect(data).to have_keys :account_id, :add_bank_uri
85
+ end
86
+ end
87
+
88
+ describe "#set_tax" do
89
+ it "sets tax of an account" do
90
+ data = it.set_tax(
91
+ account_id: "123456",
92
+ access_token: 'access_token',
93
+ taxes: [{"percent" => 10,"country" => "US","state" => "CA","zip" => "94025"}]
94
+ )
95
+
96
+ expect(data.first).to have_keys :percent, :country, :state, :zip
97
+ end
98
+ end
99
+
100
+ describe "#get_tax" do
101
+ it "gets tax of an account" do
102
+ data = it.get_tax(
103
+ account_id: "123456",
104
+ access_token: 'access_token'
105
+ )
106
+
107
+ expect(data.first).to have_keys :percent, :country, :state, :zip
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,86 @@
1
+ require "spec_helper"
2
+
3
+ describe Wepay::Api::Checkout do
4
+ let(:it) { described_class.new }
5
+ record_api_methods
6
+
7
+ describe "#show" do
8
+ it "shows the info of a checkout" do
9
+ data = it.show(
10
+ checkout_id: 1234567890
11
+ )
12
+ expect(data).to have_keys :checkout_id, :checkout_uri, :amount, :state, :type, :short_description, :fee_payer
13
+ end
14
+ end
15
+
16
+ describe "#find" do
17
+ it "finds all the checkouts of an account" do
18
+ data = it.find(
19
+ account_id: 123456
20
+ )
21
+
22
+ expect(data).to be_a Array
23
+ expect(data.first).to have_keys :checkout_id, :checkout_uri, :amount, :state, :type, :short_description, :fee_payer
24
+ end
25
+ end
26
+
27
+ describe "#create" do
28
+ it "creates a checkout" do
29
+ data = it.create(
30
+ account_id: 123456,
31
+ short_description: "Payment",
32
+ type: "GOODS",
33
+ amount: 10
34
+ )
35
+
36
+ expect(data).to have_keys :checkout_id, :checkout_uri
37
+ end
38
+ end
39
+
40
+ describe "#cancel" do
41
+ it "cancels a checkout with a reason" do
42
+ data = it.cancel(
43
+ checkout_id: 1234567890,
44
+ cancel_reason: "no reason"
45
+ )
46
+
47
+ expect(data).to have_keys :checkout_id, :state
48
+ expect(data.state).to eq 'cancelled'
49
+ end
50
+ end
51
+
52
+ describe "#refund" do
53
+ it "refunds a checkout with a reason" do
54
+ data = it.refund(
55
+ checkout_id: 1234567890,
56
+ refund_reason: "no reason"
57
+ )
58
+
59
+ expect(data).to have_keys :checkout_id, :state
60
+ expect(data.state).to eq 'refunded'
61
+ end
62
+ end
63
+
64
+ describe "#capture" do
65
+ it "captures a reserved checkout" do
66
+ data = it.capture(
67
+ checkout_id: 1234567890
68
+ )
69
+
70
+ expect(data).to have_keys :checkout_id, :state
71
+ expect(data.state).to eq 'captured'
72
+ end
73
+ end
74
+
75
+ describe "#modify" do
76
+ it "modifies a checkout" do
77
+ data = it.modify(
78
+ checkout_id: 1234567890,
79
+ callback_uri: "https://www.example.com/ipn/12345"
80
+ )
81
+
82
+ expect(data).to have_keys :checkout_id, :callback_uri
83
+ expect(data.callback_uri).to eq "https://www.example.com/ipn/12345"
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,69 @@
1
+ require "spec_helper"
2
+
3
+ describe Wepay::Api::Preapproval do
4
+ let(:it) { described_class.new }
5
+ record_api_methods
6
+
7
+ describe "#show" do
8
+ it "shows the info of a preapproval" do
9
+ data = it.show(
10
+ preapproval_id: 123456789,
11
+ access_token: "access_token"
12
+ )
13
+ expect(data).to have_keys :preapproval_id, :preapproval_uri, :manage_uri, :account_id, :short_description, :currency, :amount, :fee_payer, :state,
14
+ :redirect_uri, :app_fee, :period, :frequency, :start_time, :end_time
15
+ end
16
+ end
17
+
18
+ describe "#find" do
19
+ it "finds all the preapprovals of an account" do
20
+ data = it.find(
21
+ account_id: 123456,
22
+ access_token: "access_token"
23
+ )
24
+
25
+ expect(data).to be_a Array
26
+ expect(data.first).to have_keys :preapproval_id, :preapproval_uri, :manage_uri, :account_id, :short_description, :currency, :amount, :fee_payer, :state,
27
+ :redirect_uri, :app_fee, :period, :frequency, :start_time, :end_time
28
+ end
29
+ end
30
+
31
+ describe "#create" do
32
+ it "creates a preapproval" do
33
+ data = it.create(
34
+ short_description: "Payment",
35
+ period: "yearly",
36
+ amount: 10,
37
+ account_id: 123456,
38
+ access_token: "access_token"
39
+ )
40
+
41
+ expect(data).to have_keys :preapproval_id, :preapproval_uri
42
+ end
43
+ end
44
+
45
+ describe "#cancel" do
46
+ it "cancels a preapproval with a reason" do
47
+ data = it.cancel(
48
+ preapproval_id: 123456789,
49
+ access_token: "access_token"
50
+ )
51
+
52
+ expect(data).to have_keys :preapproval_id, :state
53
+ expect(data.state).to eq 'cancelled'
54
+ end
55
+ end
56
+
57
+ describe "#modify" do
58
+ it "modifies a preapproval" do
59
+ data = it.modify(
60
+ preapproval_id: 123456789,
61
+ callback_uri: "https://www.example.com/ipn/12345",
62
+ access_token: "access_token"
63
+ )
64
+
65
+ expect(data).to have_keys :preapproval_id, :callback_uri
66
+ expect(data.callback_uri).to eq "https://www.example.com/ipn/12345"
67
+ end
68
+ end
69
+ end