afterpay 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/README.md +1 -1
- data/afterpay.gemspec +3 -3
- data/lib/afterpay/api/order/find.rb +28 -0
- data/lib/afterpay/components/merchant.rb +6 -0
- data/lib/afterpay/components/order.rb +5 -0
- data/lib/afterpay/error_handler.rb +5 -1
- data/lib/afterpay/errors.rb +8 -1
- data/lib/afterpay/http_service.rb +1 -2
- data/lib/afterpay/version.rb +1 -1
- data/lib/afterpay.rb +2 -1
- metadata +9 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ef17010e4937b9dcd9f33a9b6cb86018c5359bbc2114ec4cecf7f2496de5a4e
|
4
|
+
data.tar.gz: 53371cb5b49385109d8cd97613af0820e77c4b0371304e8902a736861177db95
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a0c9dbed40e6a784e3cedcbbca139ebd40d23e9efc65d7cb6634de25ec20588036ae5acf81d844c08aa3de65d9e930e8b90f4154bced90ae756545c3f4029a6
|
7
|
+
data.tar.gz: 83e959ba698efe7f5fefbc777ee5df46a551234b846ad649e1450e4fe68fca1768de9f32f7a1906cf8cf4f836cb4a3f4eeaae5f8ee372326eb5c15bcbbb4b508
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -30,7 +30,7 @@ Merchant ID and Secret Key are required to work with Afterpay API
|
|
30
30
|
Afterpay.configure do |c|
|
31
31
|
c.merchant_id = 'your_merchant_id'
|
32
32
|
c.secret_key = 'your_secret_key'
|
33
|
-
c.server = 'us_or_au_server' # Default is 'https://api.
|
33
|
+
c.server = 'us_or_au_server' # Default is 'https://global-api.afterpay.com/'
|
34
34
|
c.user_agent = 'MyAfterpayModule/1.0.0 (E-Commerce Platform Name/1.0.0; PHP/7.0.0; Merchant/600032000) https://merchant.example.com' # Default is nil
|
35
35
|
end
|
36
36
|
```
|
data/afterpay.gemspec
CHANGED
@@ -23,9 +23,9 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
24
|
spec.require_paths = %w[lib]
|
25
25
|
|
26
|
-
spec.add_runtime_dependency 'faraday', '~>
|
27
|
-
spec.add_runtime_dependency 'faraday_middleware', '~>
|
28
|
-
spec.add_runtime_dependency 'hashie', '~>
|
26
|
+
spec.add_runtime_dependency 'faraday', '~> 1.0'
|
27
|
+
spec.add_runtime_dependency 'faraday_middleware', '~> 1.0'
|
28
|
+
spec.add_runtime_dependency 'hashie', '~> 4.0'
|
29
29
|
|
30
30
|
spec.add_development_dependency 'bundler', '~> 2.2.22'
|
31
31
|
spec.add_development_dependency 'codecov', '~> 0.5.2'
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Afterpay
|
4
|
+
module API
|
5
|
+
module Order
|
6
|
+
class Find < Base
|
7
|
+
def initialize(params = {})
|
8
|
+
@token = params[:token]
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
attr_reader :token
|
14
|
+
|
15
|
+
def payload
|
16
|
+
{
|
17
|
+
action: :get,
|
18
|
+
endpoint: endpoint
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
def endpoint
|
23
|
+
"#{URL}/#{token}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -12,6 +12,12 @@ module Afterpay
|
|
12
12
|
# @return [String]
|
13
13
|
# The user to redirected to this URL if the payment process is cancelled.
|
14
14
|
attr_accessor :redirect_cancel_url
|
15
|
+
|
16
|
+
# @attribute popup_origin_url
|
17
|
+
# @return [String]
|
18
|
+
# URL to receive Javascript callbacks from Afterpay (e.g. onComplete, onShippingAddressChange, etc).
|
19
|
+
# Include the scheme, hostname and port. Port is optional.
|
20
|
+
attr_accessor :popup_origin_url
|
15
21
|
end
|
16
22
|
end
|
17
23
|
end
|
@@ -62,6 +62,11 @@ module Afterpay
|
|
62
62
|
# @return [Afterpay::Components::Money]
|
63
63
|
# The shipping amount.
|
64
64
|
attr_accessor :shipping_amount
|
65
|
+
|
66
|
+
# @attribute mode
|
67
|
+
# @return [String]
|
68
|
+
# Set to `express` for an express-flow checkout.
|
69
|
+
attr_accessor :mode
|
65
70
|
end
|
66
71
|
end
|
67
72
|
end
|
@@ -11,13 +11,17 @@ module Afterpay
|
|
11
11
|
def inspect(response)
|
12
12
|
return response if response.ok?
|
13
13
|
|
14
|
-
raise ERRORS[response.status], response_message(response)
|
14
|
+
raise ERRORS[response.status].new(response_error_code(response)), response_message(response)
|
15
15
|
end
|
16
16
|
|
17
17
|
def response_message(response)
|
18
18
|
response.body.is_a?(String) ? JSON.parse(response.body)['message'] : response.message
|
19
19
|
end
|
20
20
|
|
21
|
+
def response_error_code(response)
|
22
|
+
response.body.is_a?(String) ? JSON.parse(response.body)['errorCode'] : response.body.errorCode
|
23
|
+
end
|
24
|
+
|
21
25
|
ERRORS = {
|
22
26
|
400 => BadRequestError,
|
23
27
|
401 => UnathorizedError,
|
data/lib/afterpay/errors.rb
CHANGED
@@ -1,7 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Afterpay
|
4
|
-
class BaseError
|
4
|
+
class BaseError < StandardError
|
5
|
+
attr_accessor :error_code
|
6
|
+
|
7
|
+
def initialize(error_code)
|
8
|
+
super
|
9
|
+
@error_code = error_code
|
10
|
+
end
|
11
|
+
end
|
5
12
|
|
6
13
|
class BadRequestError < BaseError; end
|
7
14
|
|
@@ -18,8 +18,7 @@ module Afterpay
|
|
18
18
|
# Afterpay default middleware stack
|
19
19
|
DEFAULT_MIDDLEWARE = proc do |builder|
|
20
20
|
builder.request :json
|
21
|
-
|
22
|
-
builder.basic_auth(*::Afterpay.configuration.values)
|
21
|
+
builder.request :basic_auth, *::Afterpay.configuration.values
|
23
22
|
|
24
23
|
builder.response :mashify
|
25
24
|
builder.response :json, content_type: /\bjson$/
|
data/lib/afterpay/version.rb
CHANGED
data/lib/afterpay.rb
CHANGED
@@ -5,6 +5,7 @@ require 'afterpay/api/configuration'
|
|
5
5
|
require 'afterpay/api/configuration/retrieve'
|
6
6
|
require 'afterpay/api/order'
|
7
7
|
require 'afterpay/api/order/create'
|
8
|
+
require 'afterpay/api/order/find'
|
8
9
|
require 'afterpay/api/payment'
|
9
10
|
require 'afterpay/api/payment/capture'
|
10
11
|
require 'afterpay/api/payment/refund'
|
@@ -62,5 +63,5 @@ module Afterpay
|
|
62
63
|
end
|
63
64
|
end
|
64
65
|
|
65
|
-
DEFAULT_SERVER = 'https://api.
|
66
|
+
DEFAULT_SERVER = 'https://global-api.afterpay.com/'
|
66
67
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: afterpay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergey Vygovsky
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: exe
|
13
13
|
cert_chain: []
|
14
|
-
date: 2021-
|
14
|
+
date: 2021-09-09 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: faraday
|
@@ -19,60 +19,42 @@ dependencies:
|
|
19
19
|
requirements:
|
20
20
|
- - "~>"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '0
|
23
|
-
- - ">="
|
24
|
-
- !ruby/object:Gem::Version
|
25
|
-
version: 0.15.3
|
22
|
+
version: '1.0'
|
26
23
|
type: :runtime
|
27
24
|
prerelease: false
|
28
25
|
version_requirements: !ruby/object:Gem::Requirement
|
29
26
|
requirements:
|
30
27
|
- - "~>"
|
31
28
|
- !ruby/object:Gem::Version
|
32
|
-
version: '0
|
33
|
-
- - ">="
|
34
|
-
- !ruby/object:Gem::Version
|
35
|
-
version: 0.15.3
|
29
|
+
version: '1.0'
|
36
30
|
- !ruby/object:Gem::Dependency
|
37
31
|
name: faraday_middleware
|
38
32
|
requirement: !ruby/object:Gem::Requirement
|
39
33
|
requirements:
|
40
34
|
- - "~>"
|
41
35
|
- !ruby/object:Gem::Version
|
42
|
-
version: '0
|
43
|
-
- - ">="
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: 0.12.2
|
36
|
+
version: '1.0'
|
46
37
|
type: :runtime
|
47
38
|
prerelease: false
|
48
39
|
version_requirements: !ruby/object:Gem::Requirement
|
49
40
|
requirements:
|
50
41
|
- - "~>"
|
51
42
|
- !ruby/object:Gem::Version
|
52
|
-
version: '0
|
53
|
-
- - ">="
|
54
|
-
- !ruby/object:Gem::Version
|
55
|
-
version: 0.12.2
|
43
|
+
version: '1.0'
|
56
44
|
- !ruby/object:Gem::Dependency
|
57
45
|
name: hashie
|
58
46
|
requirement: !ruby/object:Gem::Requirement
|
59
47
|
requirements:
|
60
|
-
- - ">="
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
version: 3.6.0
|
63
48
|
- - "~>"
|
64
49
|
- !ruby/object:Gem::Version
|
65
|
-
version: '
|
50
|
+
version: '4.0'
|
66
51
|
type: :runtime
|
67
52
|
prerelease: false
|
68
53
|
version_requirements: !ruby/object:Gem::Requirement
|
69
54
|
requirements:
|
70
|
-
- - ">="
|
71
|
-
- !ruby/object:Gem::Version
|
72
|
-
version: 3.6.0
|
73
55
|
- - "~>"
|
74
56
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
57
|
+
version: '4.0'
|
76
58
|
- !ruby/object:Gem::Dependency
|
77
59
|
name: bundler
|
78
60
|
requirement: !ruby/object:Gem::Requirement
|
@@ -257,6 +239,7 @@ files:
|
|
257
239
|
- lib/afterpay/api/configuration/retrieve.rb
|
258
240
|
- lib/afterpay/api/order.rb
|
259
241
|
- lib/afterpay/api/order/create.rb
|
242
|
+
- lib/afterpay/api/order/find.rb
|
260
243
|
- lib/afterpay/api/payment.rb
|
261
244
|
- lib/afterpay/api/payment/auth.rb
|
262
245
|
- lib/afterpay/api/payment/capture.rb
|