afterpay 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +7 -0
  2. data/.circleci/config.yml +24 -0
  3. data/.gitignore +13 -0
  4. data/.rspec +3 -0
  5. data/.rubocop.yml +5 -0
  6. data/.travis.yml +5 -0
  7. data/Gemfile +8 -0
  8. data/LICENSE +224 -0
  9. data/README.md +103 -0
  10. data/Rakefile +8 -0
  11. data/afterpay.gemspec +41 -0
  12. data/bin/console +15 -0
  13. data/bin/setup +8 -0
  14. data/lib/afterpay/api/base.rb +37 -0
  15. data/lib/afterpay/api/configuration/retrieve.rb +20 -0
  16. data/lib/afterpay/api/configuration.rb +9 -0
  17. data/lib/afterpay/api/order/create.rb +27 -0
  18. data/lib/afterpay/api/order.rb +9 -0
  19. data/lib/afterpay/api/payment/auth.rb +29 -0
  20. data/lib/afterpay/api/payment/capture.rb +29 -0
  21. data/lib/afterpay/api/payment/deferred_capture.rb +30 -0
  22. data/lib/afterpay/api/payment/find.rb +28 -0
  23. data/lib/afterpay/api/payment/refund.rb +30 -0
  24. data/lib/afterpay/api/payment/void.rb +30 -0
  25. data/lib/afterpay/api/payment.rb +9 -0
  26. data/lib/afterpay/callable.rb +11 -0
  27. data/lib/afterpay/components/base.rb +14 -0
  28. data/lib/afterpay/components/consumer.rb +27 -0
  29. data/lib/afterpay/components/contact.rb +52 -0
  30. data/lib/afterpay/components/courier.rb +27 -0
  31. data/lib/afterpay/components/discount.rb +17 -0
  32. data/lib/afterpay/components/item.rb +48 -0
  33. data/lib/afterpay/components/merchant.rb +17 -0
  34. data/lib/afterpay/components/money.rb +17 -0
  35. data/lib/afterpay/components/order.rb +67 -0
  36. data/lib/afterpay/components/payment.rb +22 -0
  37. data/lib/afterpay/components/payment_event.rb +17 -0
  38. data/lib/afterpay/components/refund.rb +29 -0
  39. data/lib/afterpay/error_handler.rb +38 -0
  40. data/lib/afterpay/errors.rb +31 -0
  41. data/lib/afterpay/http_service/request.rb +46 -0
  42. data/lib/afterpay/http_service/response.rb +34 -0
  43. data/lib/afterpay/http_service.rb +30 -0
  44. data/lib/afterpay/initializable.rb +27 -0
  45. data/lib/afterpay/representable.rb +47 -0
  46. data/lib/afterpay/version.rb +5 -0
  47. data/lib/afterpay.rb +66 -0
  48. metadata +311 -0
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'afterpay'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'afterpay/callable'
4
+ require 'afterpay/error_handler'
5
+ require 'afterpay/http_service'
6
+ require 'afterpay/http_service/request'
7
+ require 'afterpay/http_service/response'
8
+
9
+ module Afterpay
10
+ module API
11
+ class Base < Callable
12
+ def call
13
+ ::Afterpay::ErrorHandler.inspect(response)
14
+ end
15
+
16
+ private
17
+
18
+ def response
19
+ @response ||= ::Afterpay::HTTPService::Response.new(
20
+ status: raw_response.status.to_i,
21
+ body: raw_response.body,
22
+ headers: raw_response.headers
23
+ )
24
+ end
25
+
26
+ def raw_response
27
+ @raw_response ||= request.perform(payload)
28
+ end
29
+
30
+ def request
31
+ @request ||= ::Afterpay::HTTPService::Request.new(
32
+ ::Afterpay::HTTPService.configuration
33
+ )
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Afterpay
4
+ module API
5
+ module Configuration
6
+ class Retrieve < Base
7
+ private
8
+
9
+ def payload
10
+ {
11
+ action: :get,
12
+ endpoint: endpoint
13
+ }
14
+ end
15
+
16
+ def endpoint; URL; end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Afterpay
4
+ module API
5
+ module Configuration
6
+ URL = 'v2/configuration'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Afterpay
4
+ module API
5
+ module Order
6
+ class Create < Base
7
+ def initialize(params = {})
8
+ @order = params[:order]
9
+ end
10
+
11
+ private
12
+
13
+ attr_reader :order
14
+
15
+ def payload
16
+ {
17
+ action: :post,
18
+ body: order.as_json,
19
+ endpoint: endpoint
20
+ }
21
+ end
22
+
23
+ def endpoint; URL; end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Afterpay
4
+ module API
5
+ module Order
6
+ URL = 'v2/checkouts'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Afterpay
4
+ module API
5
+ module Payment
6
+ class Auth < Base
7
+ def initialize(params = {})
8
+ @payment = params[:payment]
9
+ end
10
+
11
+ private
12
+
13
+ attr_reader :payment
14
+
15
+ def payload
16
+ {
17
+ action: :post,
18
+ body: payment.as_json,
19
+ endpoint: endpoint
20
+ }
21
+ end
22
+
23
+ def endpoint
24
+ "#{URL}/auth"
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Afterpay
4
+ module API
5
+ module Payment
6
+ class Capture < Base
7
+ def initialize(params = {})
8
+ @payment = params[:payment]
9
+ end
10
+
11
+ private
12
+
13
+ attr_reader :payment
14
+
15
+ def payload
16
+ {
17
+ action: :post,
18
+ body: payment.as_json,
19
+ endpoint: endpoint
20
+ }
21
+ end
22
+
23
+ def endpoint
24
+ "#{URL}/capture"
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Afterpay
4
+ module API
5
+ module Payment
6
+ class DeferredCapture < Base
7
+ def initialize(params = {})
8
+ @payment = params[:payment]
9
+ @order_id = params[:order_id]
10
+ end
11
+
12
+ private
13
+
14
+ attr_reader :payment, :order_id
15
+
16
+ def payload
17
+ {
18
+ action: :post,
19
+ body: payment.as_json,
20
+ endpoint: endpoint
21
+ }
22
+ end
23
+
24
+ def endpoint
25
+ "#{URL}/#{order_id}/capture"
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Afterpay
4
+ module API
5
+ module Payment
6
+ class Find < Base
7
+ def initialize(params = {})
8
+ @order_id = params[:order_id]
9
+ end
10
+
11
+ private
12
+
13
+ attr_reader :order_id
14
+
15
+ def payload
16
+ {
17
+ action: :get,
18
+ endpoint: endpoint
19
+ }
20
+ end
21
+
22
+ def endpoint
23
+ "#{URL}/#{order_id}"
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Afterpay
4
+ module API
5
+ module Payment
6
+ class Refund < Base
7
+ def initialize(params = {})
8
+ @order_id = params[:order_id]
9
+ @refund = params[:refund]
10
+ end
11
+
12
+ private
13
+
14
+ attr_reader :refund, :order_id
15
+
16
+ def payload
17
+ {
18
+ action: :post,
19
+ body: refund.as_json,
20
+ endpoint: endpoint
21
+ }
22
+ end
23
+
24
+ def endpoint
25
+ "#{URL}/#{order_id}/refund"
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Afterpay
4
+ module API
5
+ module Payment
6
+ class Void < Base
7
+ def initialize(params = {})
8
+ @order_id = params[:order_id]
9
+ @payment = params[:payment]
10
+ end
11
+
12
+ private
13
+
14
+ attr_reader :payment, :order_id
15
+
16
+ def payload
17
+ {
18
+ action: :post,
19
+ body: payment.as_json,
20
+ endpoint: endpoint
21
+ }
22
+ end
23
+
24
+ def endpoint
25
+ "#{URL}/#{order_id}/void"
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Afterpay
4
+ module API
5
+ module Payment
6
+ URL = 'v2/payments'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Afterpay
4
+ class Callable
5
+ def self.call(*args)
6
+ new(*args).call.tap do |result|
7
+ return yield result if block_given?
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'afterpay/initializable'
4
+ require 'afterpay/representable'
5
+
6
+ module Afterpay
7
+ module Components
8
+ # @note This class is used as parent class for all other Afterpay models
9
+ class Base
10
+ include Representable
11
+ include Initializable
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Afterpay
4
+ module Components
5
+ class Consumer < Base
6
+ # @attribute phone_number
7
+ # @return [String]
8
+ # The consumer's phone number.
9
+ attr_accessor :phone_number
10
+
11
+ # @attribute given_names
12
+ # @return [String]
13
+ # The consumer's given names.
14
+ attr_accessor :given_names
15
+
16
+ # @attribute surname
17
+ # @return [String]
18
+ # The consumer's surname.
19
+ attr_accessor :surname
20
+
21
+ # @attribute email
22
+ # @return [String]
23
+ # The consumer's email.
24
+ attr_accessor :email
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Afterpay
4
+ module Components
5
+ class Contact < Base
6
+ # @attribute name
7
+ # @return [String]
8
+ # Full name of contact. Maximum length is 255 characters.
9
+ attr_accessor :name
10
+
11
+ # @attribute line1
12
+ # @return [String]
13
+ # Street address. Maximum length is 128 characters.
14
+ attr_accessor :line1
15
+
16
+ # @attribute line2
17
+ # @return [String]
18
+ # Second line of the address. Maximum length is 128 characters.
19
+ attr_accessor :line2
20
+
21
+ # @attribute area1
22
+ # @return [String]
23
+ # City or suburb. Maximum length is 128 characters.
24
+ attr_accessor :area1
25
+
26
+ # @attribute area2
27
+ # @return [String]
28
+ # Suburb or village or local area. Maximum length is 128 characters.
29
+ attr_accessor :area2
30
+
31
+ # @attribute region
32
+ # @return [String]
33
+ # Region or state name. Maximum length is 128 characters.
34
+ attr_accessor :region
35
+
36
+ # @attribute postcode
37
+ # @return [String]
38
+ # The postal code, which is the zip code or equivalent. Maximum length is 128 characters.
39
+ attr_accessor :postcode
40
+
41
+ # @attribute country_code
42
+ # @return [String]
43
+ # The two-character ISO 3166-1 country code.
44
+ attr_accessor :country_code
45
+
46
+ # @attribute phone_number
47
+ # @return [String]
48
+ # The phone number, in E.123 format. Maximum length is 32 characters.
49
+ attr_accessor :phone_number
50
+ end
51
+ end
52
+ end