afterpay-sdk 2.0.0 → 2.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.circleci/config.yml +54 -0
- data/CHANGELOG.md +31 -0
- data/Gemfile.lock +24 -3
- data/README.md +17 -9
- data/afterpay-sdk.gemspec +1 -0
- data/lib/afterpay/client.rb +1 -1
- data/lib/afterpay/config.rb +2 -1
- data/lib/afterpay/consumer.rb +5 -5
- data/lib/afterpay/discount.rb +1 -1
- data/lib/afterpay/item.rb +9 -11
- data/lib/afterpay/order.rb +3 -3
- data/lib/afterpay/payment.rb +32 -23
- data/lib/afterpay/payment_event.rb +21 -7
- data/lib/afterpay/refund.rb +36 -11
- data/lib/afterpay/shipping_courier.rb +18 -5
- data/lib/afterpay/version.rb +1 -1
- metadata +19 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb292a6cb6b785f6740765d4ccf6b4cc7c2f85dce07cb600bba1e2bb022a1d6d
|
4
|
+
data.tar.gz: 62bf9d375026ae439655ba8e4b3acc2efbb4b875e24b0ee0e720c95e030a5eb3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 599c360d5665eef5641188d2844a8b49aabeeb7e32a8a72fdab941f94213c1b86438c516ebb024baf72fe4b4481b873f4fbf94999672d446a6bb923b90f0b748
|
7
|
+
data.tar.gz: e673d5b3e0069ec7a4e4a18c53d9f13dbc88b7f01ba96777f06c0838fa5e230c6da3017c1482fab862bbd9f17772a81e5a4fcdf4be06de5c2caad12a7d4214ff
|
@@ -0,0 +1,54 @@
|
|
1
|
+
version: 2
|
2
|
+
jobs:
|
3
|
+
build:
|
4
|
+
working_directory: ~/YourMechanic/afterpay-sdk
|
5
|
+
parallelism: 1
|
6
|
+
shell: /bin/bash --login
|
7
|
+
|
8
|
+
environment:
|
9
|
+
CIRCLE_ARTIFACTS: /tmp/circleci-artifacts
|
10
|
+
CIRCLE_TEST_REPORTS: /tmp/circleci-test-results
|
11
|
+
docker:
|
12
|
+
- image: circleci/ruby:2.6.2
|
13
|
+
steps:
|
14
|
+
- checkout
|
15
|
+
- run: mkdir -p $CIRCLE_ARTIFACTS $CIRCLE_TEST_REPORTS
|
16
|
+
- restore_cache:
|
17
|
+
keys:
|
18
|
+
# This branch if available
|
19
|
+
- v2-dep-{{ .Branch }}-
|
20
|
+
# Default branch if not
|
21
|
+
- v2-dep-master-
|
22
|
+
# Any branch if there are none on the default branch - this should be unnecessary if you have your default branch configured correctly
|
23
|
+
- v2-dep-
|
24
|
+
- run:
|
25
|
+
name: Install bundler for afterpay-sdk
|
26
|
+
working_directory: ~/YourMechanic/afterpay-sdk
|
27
|
+
command: gem install bundler:2.2.11
|
28
|
+
- run:
|
29
|
+
name: Install Gems for afterpay-sdk
|
30
|
+
working_directory: ~/YourMechanic/afterpay-sdk
|
31
|
+
command: bundle install
|
32
|
+
# Save dependency cache
|
33
|
+
- save_cache:
|
34
|
+
key: v2-dep-{{ .Branch }}-{{ epoch }}
|
35
|
+
paths:
|
36
|
+
- vendor/bundle
|
37
|
+
- ~/virtualenvs
|
38
|
+
- ~/.m2
|
39
|
+
- ~/.ivy2
|
40
|
+
- ~/.bundle
|
41
|
+
- run:
|
42
|
+
working_directory: ~/YourMechanic/afterpay-sdk
|
43
|
+
command: bundle exec rubocop
|
44
|
+
- run:
|
45
|
+
working_directory: ~/YourMechanic/afterpay-sdk
|
46
|
+
command: bundle exec rspec --colour --drb --profile -fd --format progress $(circleci tests glob "spec/*_spec.rb" | circleci tests split)
|
47
|
+
- store_test_results:
|
48
|
+
path: /tmp/circleci-test-results
|
49
|
+
- store_artifacts:
|
50
|
+
path: /tmp/circleci-artifacts
|
51
|
+
- store_artifacts:
|
52
|
+
path: /tmp/circleci-test-results
|
53
|
+
- store_artifacts:
|
54
|
+
path: afterpay-sdk/coverage
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
## [Unreleased]
|
2
|
+
|
3
|
+
## [2.0.0] - 2021-06-02
|
4
|
+
|
5
|
+
- Initial release
|
6
|
+
|
7
|
+
### 2.0.1 - 2021-07-05
|
8
|
+
|
9
|
+
* bug-fixes
|
10
|
+
* Correct the from_response method by not directly calling new with response but formatting the amount and then calling new with the attributes. The afterpay-sdk gem follows the Data Models attibutes data types as in v2 doc. As per the doc amount attibute of Refund or PaymentEvent object is a Money object so when the developer calls new he need to supply the money object however we use from_response method where we convert amount in response to money object using utils. (by @sachinsaxena1996)
|
11
|
+
* Fix refund objects attributes. add sucess? to refund model. Fix id be string in PaymentEvent. (by @sachinsaxena1996)
|
12
|
+
* Do not directly call new with response.body use from_response instead. Change done as attribute were blank in Refund.execute. (by @sachinsaxena1996)
|
13
|
+
* Fixed issue with error object of Refund object (by @sachinsaxena1996)
|
14
|
+
* enhancement
|
15
|
+
* respond with objects array in payment response objects for events and refunds attributes. (by @sachinsaxena1996)
|
16
|
+
* Added rspec for data models (by @sachinsaxena1996)
|
17
|
+
|
18
|
+
### 2.0.2 - 2021-08-17
|
19
|
+
|
20
|
+
* enhancement
|
21
|
+
* Allow user agent to be configurable (by @siddyg)
|
22
|
+
|
23
|
+
### 2.0.3 - 2021-08-20
|
24
|
+
|
25
|
+
* enhancement
|
26
|
+
* Expose declined? method in payment object, this is primarily applicable only for authorization (by @siddyg)
|
27
|
+
|
28
|
+
### 2.0.4 - 2021-08-24
|
29
|
+
|
30
|
+
* enhancement
|
31
|
+
* added circleci support (by @sachinsaxena1996)
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
afterpay-sdk (2.0.
|
4
|
+
afterpay-sdk (2.0.4)
|
5
5
|
faraday (>= 0.8, < 1.0)
|
6
6
|
faraday_middleware (~> 0.13.1)
|
7
7
|
money (>= 6.7.1, < 7.0.0)
|
@@ -11,8 +11,9 @@ GEM
|
|
11
11
|
specs:
|
12
12
|
addressable (2.6.0)
|
13
13
|
public_suffix (>= 2.0.2, < 4.0)
|
14
|
+
ast (2.4.2)
|
14
15
|
coderay (1.1.2)
|
15
|
-
concurrent-ruby (1.1.
|
16
|
+
concurrent-ruby (1.1.9)
|
16
17
|
coveralls (0.8.22)
|
17
18
|
json (>= 1.8, < 3)
|
18
19
|
simplecov (~> 0.16.1)
|
@@ -29,18 +30,24 @@ GEM
|
|
29
30
|
faraday_middleware (0.13.1)
|
30
31
|
faraday (>= 0.7.4, < 1.0)
|
31
32
|
hashdiff (0.3.8)
|
32
|
-
i18n (1.8.
|
33
|
+
i18n (1.8.10)
|
33
34
|
concurrent-ruby (~> 1.0)
|
34
35
|
json (2.3.1)
|
35
36
|
method_source (0.9.2)
|
36
37
|
money (6.16.0)
|
37
38
|
i18n (>= 0.6.4, <= 2)
|
38
39
|
multipart-post (2.1.1)
|
40
|
+
parallel (1.20.1)
|
41
|
+
parser (3.0.2.0)
|
42
|
+
ast (~> 2.4.1)
|
39
43
|
pry (0.12.2)
|
40
44
|
coderay (~> 1.1.0)
|
41
45
|
method_source (~> 0.9.0)
|
42
46
|
public_suffix (3.0.3)
|
47
|
+
rainbow (3.0.0)
|
43
48
|
rake (12.3.3)
|
49
|
+
regexp_parser (2.1.1)
|
50
|
+
rexml (3.2.5)
|
44
51
|
rspec (3.8.0)
|
45
52
|
rspec-core (~> 3.8.0)
|
46
53
|
rspec-expectations (~> 3.8.0)
|
@@ -54,6 +61,18 @@ GEM
|
|
54
61
|
diff-lcs (>= 1.2.0, < 2.0)
|
55
62
|
rspec-support (~> 3.8.0)
|
56
63
|
rspec-support (3.8.0)
|
64
|
+
rubocop (1.19.1)
|
65
|
+
parallel (~> 1.10)
|
66
|
+
parser (>= 3.0.0.0)
|
67
|
+
rainbow (>= 2.2.2, < 4.0)
|
68
|
+
regexp_parser (>= 1.8, < 3.0)
|
69
|
+
rexml
|
70
|
+
rubocop-ast (>= 1.9.1, < 2.0)
|
71
|
+
ruby-progressbar (~> 1.7)
|
72
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
73
|
+
rubocop-ast (1.11.0)
|
74
|
+
parser (>= 3.0.1.1)
|
75
|
+
ruby-progressbar (1.11.0)
|
57
76
|
safe_yaml (1.0.5)
|
58
77
|
simplecov (0.16.1)
|
59
78
|
docile (~> 1.1)
|
@@ -64,6 +83,7 @@ GEM
|
|
64
83
|
tins (~> 1.0)
|
65
84
|
thor (0.19.4)
|
66
85
|
tins (1.20.2)
|
86
|
+
unicode-display_width (2.0.0)
|
67
87
|
vcr (4.0.0)
|
68
88
|
webmock (3.5.1)
|
69
89
|
addressable (>= 2.3.6)
|
@@ -81,6 +101,7 @@ DEPENDENCIES
|
|
81
101
|
pry
|
82
102
|
rake (~> 12.3, >= 12.3.3)
|
83
103
|
rspec (~> 3.0)
|
104
|
+
rubocop (~> 1.7)
|
84
105
|
simplecov
|
85
106
|
vcr (~> 4.0)
|
86
107
|
webmock (~> 3.5, >= 3.5.1)
|
data/README.md
CHANGED
@@ -36,19 +36,27 @@ Afterpay.configure do |config|
|
|
36
36
|
# config.env = "sandbox" # "live"
|
37
37
|
|
38
38
|
# Sets the user agent header for Afterpay requests
|
39
|
-
# Refer https://developers.afterpay.com/afterpay-online/
|
40
|
-
#
|
39
|
+
# Refer https://developers.afterpay.com/afterpay-online/docs/user-agent-header-1
|
40
|
+
# Refer https://developers.afterpay.com/afterpay-online/reference#user-agent-header
|
41
41
|
# Example
|
42
|
-
# config.
|
43
|
-
|
42
|
+
# config.afterpay_plugin = 'MyAfterpayModule/1.0.0'
|
43
|
+
# config.platform = 'Rails/3.2.22.3'
|
44
|
+
# config.system_information = 'RUBY/2.3.8'
|
45
|
+
# config.merchant_website_url = <merchant_website_url>
|
46
|
+
|
47
|
+
config.afterpay_plugin = <afterpay_plugin>
|
48
|
+
config.platform = <platform>
|
49
|
+
config.system_information = <system_information>
|
50
|
+
config.merchant_website_url = <merchant_website_url>
|
51
|
+
|
44
52
|
end
|
45
53
|
```
|
46
54
|
|
47
55
|
### Creating an Order
|
48
56
|
|
49
|
-
[api docs](https://
|
57
|
+
[api docs](https://developers.afterpay.com/afterpay-online/reference#checkouts)
|
50
58
|
|
51
|
-
Order accepts a [Consumer](YourMechanic/afterpay-sdk#consumer-object) and an array of [Item](YourMechanic/afterpay-sdk#item-object) object which are required.
|
59
|
+
Order accepts a [Consumer](https://github.com/YourMechanic/afterpay-sdk#consumer-object) and an array of [Item](https://github.com/YourMechanic/afterpay-sdk#item-object) object which are required.
|
52
60
|
|
53
61
|
```ruby
|
54
62
|
order = Afterpay::Order.create(
|
@@ -57,7 +65,7 @@ order = Afterpay::Order.create(
|
|
57
65
|
items: [<Afterpay::Item>],
|
58
66
|
success_url: <String>,
|
59
67
|
cancel_url: <String>,
|
60
|
-
|
68
|
+
merchant_reference: <String>,
|
61
69
|
tax: <Money>,
|
62
70
|
shipping: <Money | optional>,
|
63
71
|
discounts: [<Afterpay::Discount | optional>],
|
@@ -94,7 +102,7 @@ order.error
|
|
94
102
|
```ruby
|
95
103
|
payment = Afterpay::Payment.execute(
|
96
104
|
token: token <String>,
|
97
|
-
|
105
|
+
merchant_reference: "checkout-1" <String>
|
98
106
|
)
|
99
107
|
=> <Afterpay::Payment ...>
|
100
108
|
|
@@ -115,7 +123,7 @@ For Auth
|
|
115
123
|
Afterpay::Payment.execute_auth(request_id: 'fjfwwwjfj090292920', token: '002.v4krg5qpii1tbp0kvr261rf3p1k5jfe2fin', merchant_reference: '100101382')
|
116
124
|
|
117
125
|
For executing deferred payment
|
118
|
-
Afterpay::Payment.execute_deferred_payment(request_id: 'ppjjjkjk',
|
126
|
+
Afterpay::Payment.execute_deferred_payment(request_id: 'ppjjjkjk', merchant_reference: '100101382', amount: mony, payment_event_merchant_reference: '', order_id: 100101524323)
|
119
127
|
```
|
120
128
|
|
121
129
|
### Void payment
|
data/afterpay-sdk.gemspec
CHANGED
@@ -38,6 +38,7 @@ Gem::Specification.new do |spec|
|
|
38
38
|
spec.add_development_dependency "pry"
|
39
39
|
spec.add_development_dependency "rake", "~> 12.3", ">= 12.3.3"
|
40
40
|
spec.add_development_dependency "rspec", "~> 3.0"
|
41
|
+
spec.add_development_dependency 'rubocop', '~> 1.7'
|
41
42
|
|
42
43
|
spec.add_dependency "faraday", ">= 0.8", "< 1.0"
|
43
44
|
spec.add_dependency "faraday_middleware", "~> 0.13.1"
|
data/lib/afterpay/client.rb
CHANGED
@@ -43,7 +43,7 @@ module Afterpay
|
|
43
43
|
Faraday.new(url: self.class.server_url) do |conn|
|
44
44
|
conn.use ErrorMiddleware if Afterpay.config.raise_errors
|
45
45
|
conn.authorization "Basic", self.class.auth_token
|
46
|
-
|
46
|
+
conn.headers["User-Agent"] = "#{Afterpay.config.afterpay_plugin} (#{Afterpay.config.platform}; #{Afterpay.config.system_information}; Merchant/#{Afterpay.config.app_id}) #{Afterpay.config.merchant_website_url}"
|
47
47
|
|
48
48
|
conn.request :json
|
49
49
|
conn.response :json, content_type: "application/json", parser_options: { symbolize_names: true }
|
data/lib/afterpay/config.rb
CHANGED
@@ -5,7 +5,8 @@ module Afterpay
|
|
5
5
|
attr_accessor :app_id, :secret, :env, :raise_errors,
|
6
6
|
:type, :maximum_amount, :minimum_amount,
|
7
7
|
:description, :currency, :skip_remote_config,
|
8
|
-
:
|
8
|
+
:afterpay_plugin, :platform,
|
9
|
+
:system_information, :merchant_website_url
|
9
10
|
|
10
11
|
def initialize
|
11
12
|
@env = "sandbox"
|
data/lib/afterpay/consumer.rb
CHANGED
@@ -4,11 +4,11 @@ module Afterpay
|
|
4
4
|
class Consumer
|
5
5
|
attr_accessor :email, :phone, :first_name, :last_name
|
6
6
|
|
7
|
-
def initialize(
|
8
|
-
@email = email
|
9
|
-
@phone = phone
|
10
|
-
@first_name = first_name
|
11
|
-
@last_name = last_name
|
7
|
+
def initialize(attributes = {})
|
8
|
+
@email = attributes[:email]
|
9
|
+
@phone = attributes[:phone] || ""
|
10
|
+
@first_name = attributes[:first_name] || ""
|
11
|
+
@last_name = attributes[:last_name] || ""
|
12
12
|
end
|
13
13
|
|
14
14
|
def to_hash
|
data/lib/afterpay/discount.rb
CHANGED
data/lib/afterpay/item.rb
CHANGED
@@ -6,18 +6,16 @@ module Afterpay
|
|
6
6
|
class Item
|
7
7
|
attr_accessor :name, :sku, :quantity, :page_url, :image_url, :price, :categories, :estimated_shipment_date
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
@
|
12
|
-
@
|
13
|
-
@
|
14
|
-
@
|
15
|
-
@
|
16
|
-
@
|
17
|
-
@
|
18
|
-
@estimated_shipment_date = estimated_shipment_date
|
9
|
+
def initialize(attributes = {})
|
10
|
+
@name = attributes[:name]
|
11
|
+
@sku = attributes[:sku] || ""
|
12
|
+
@quantity = attributes[:quantity]
|
13
|
+
@price = attributes[:price]
|
14
|
+
@page_url = attributes[:page_url] || ""
|
15
|
+
@image_url = attributes[:image_url] || ""
|
16
|
+
@categories = attributes[:categories] || []
|
17
|
+
@estimated_shipment_date = attributes[:estimated_shipment_date] || ""
|
19
18
|
end
|
20
|
-
# rubocop:enable Metrics/ParameterLists
|
21
19
|
|
22
20
|
def to_hash
|
23
21
|
{
|
data/lib/afterpay/order.rb
CHANGED
@@ -4,7 +4,7 @@ module Afterpay
|
|
4
4
|
# The Order object for creating an order to `/v2/checkouts`
|
5
5
|
class Order
|
6
6
|
attr_accessor :total, :consumer, :items, :shipping, :tax, :discounts,
|
7
|
-
:billing, :shipping_address, :billing_address, :
|
7
|
+
:billing, :shipping_address, :billing_address, :merchant_reference,
|
8
8
|
:payment_type, :success_url, :cancel_url, :redirect_checkout_url
|
9
9
|
|
10
10
|
attr_reader :expiry, :token, :error
|
@@ -77,11 +77,11 @@ module Afterpay
|
|
77
77
|
redirectConfirmUrl: success_url,
|
78
78
|
redirectCancelUrl: cancel_url
|
79
79
|
},
|
80
|
-
merchantReference:
|
80
|
+
merchantReference: merchant_reference,
|
81
81
|
taxAmount: tax,
|
82
82
|
paymentType: payment_type
|
83
83
|
}
|
84
|
-
data[items] = items.map(&:to_hash) if items
|
84
|
+
data[:items] = items.map(&:to_hash) if items
|
85
85
|
data[:taxAmount] = Utils::Money.api_hash(tax) if tax
|
86
86
|
data[:shippingAmount] = Utils::Money.api_hash(shipping) if shipping
|
87
87
|
data[:discounts] = discounts.map(&:to_hash) if discounts
|
data/lib/afterpay/payment.rb
CHANGED
@@ -8,42 +8,52 @@ module Afterpay
|
|
8
8
|
attr_accessor :id, :token, :status, :created, :original_amount, :open_to_capture_amount,
|
9
9
|
:payment_state, :merchant_reference, :refunds, :order, :events, :error
|
10
10
|
|
11
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
12
|
+
# rubocop:disable Metrics/PerceivedComplexity
|
13
|
+
|
11
14
|
# Initialize Payment from response
|
12
|
-
def initialize(attributes)
|
13
|
-
@id = attributes[:id]
|
14
|
-
@token = attributes[:token]
|
15
|
-
@status = attributes[:status]
|
16
|
-
@created = attributes[:created]
|
17
|
-
@original_amount = Utils::Money.from_response(attributes[:originalAmount])
|
18
|
-
@open_to_capture_amount = Utils::Money.from_response(attributes[:openToCaptureAmount])
|
19
|
-
@payment_state = attributes[:paymentState]
|
20
|
-
@merchant_reference = attributes[:merchantReference]
|
21
|
-
@refunds = attributes[:refunds]
|
22
|
-
@order = Order.from_response(attributes[:orderDetails])
|
23
|
-
@events = attributes[:events]
|
15
|
+
def initialize(attributes = {})
|
16
|
+
@id = attributes[:id] || ""
|
17
|
+
@token = attributes[:token] || ""
|
18
|
+
@status = attributes[:status] || ""
|
19
|
+
@created = attributes[:created] || ""
|
20
|
+
@original_amount = Utils::Money.from_response(attributes[:originalAmount]) || Money.from_amount(0)
|
21
|
+
@open_to_capture_amount = Utils::Money.from_response(attributes[:openToCaptureAmount]) || Money.from_amount(0)
|
22
|
+
@payment_state = attributes[:paymentState] || ""
|
23
|
+
@merchant_reference = attributes[:merchantReference] || ""
|
24
|
+
@refunds = attributes[:refunds].map { |refund| Refund.from_response(refund) } || [] unless attributes[:refunds].nil?
|
25
|
+
@order = Order.from_response(attributes[:orderDetails]) || Afterpay::Order.new
|
26
|
+
@events = attributes[:events].map { |event| PaymentEvent.from_response(event) } || [] unless attributes[:events].nil?
|
24
27
|
@error = Error.new(attributes) if attributes[:errorId]
|
25
28
|
end
|
26
29
|
|
30
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
31
|
+
# rubocop:enable Metrics/PerceivedComplexity
|
32
|
+
|
27
33
|
def success?
|
28
34
|
@status == "APPROVED"
|
29
35
|
end
|
30
36
|
|
37
|
+
def declined?
|
38
|
+
@status == "DECLINED"
|
39
|
+
end
|
40
|
+
|
31
41
|
# Executes the Payment
|
32
42
|
#
|
33
43
|
# @param token [String] the Order token
|
34
|
-
# @param
|
44
|
+
# @param merchant_reference [String] the merchant_reference for payment
|
35
45
|
# @return [Payment] the Payment object
|
36
|
-
def self.execute(token:,
|
46
|
+
def self.execute(token:, merchant_reference: nil)
|
37
47
|
request = Afterpay.client.post("/v2/payments/capture") do |req|
|
38
48
|
req.body = {
|
39
49
|
token: token,
|
40
|
-
|
50
|
+
merchantReference: merchant_reference
|
41
51
|
}
|
42
52
|
end
|
43
53
|
new(request.body)
|
44
54
|
end
|
45
55
|
|
46
|
-
def self.execute_auth(
|
56
|
+
def self.execute_auth(token:, request_id: nil, merchant_reference: nil)
|
47
57
|
request = Afterpay.client.post("/v2/payments/auth") do |req|
|
48
58
|
req.body = {
|
49
59
|
requestId: request_id,
|
@@ -54,12 +64,12 @@ module Afterpay
|
|
54
64
|
new(request.body)
|
55
65
|
end
|
56
66
|
|
57
|
-
def self.execute_deferred_payment(
|
58
|
-
payment_event_merchant_reference
|
67
|
+
def self.execute_deferred_payment(amount:, order_id:, request_id: nil, merchant_reference: nil,
|
68
|
+
payment_event_merchant_reference: nil)
|
59
69
|
request = Afterpay.client.post("/v2/payments/#{order_id}/capture") do |req|
|
60
70
|
req.body = {
|
61
71
|
requestId: request_id,
|
62
|
-
|
72
|
+
merchantReference: merchant_reference,
|
63
73
|
amount: Utils::Money.api_hash(amount),
|
64
74
|
paymentEventMerchantReference: payment_event_merchant_reference
|
65
75
|
}
|
@@ -67,7 +77,7 @@ module Afterpay
|
|
67
77
|
new(request.body)
|
68
78
|
end
|
69
79
|
|
70
|
-
def self.execute_void(
|
80
|
+
def self.execute_void(order_id:, amount:, request_id: nil)
|
71
81
|
request = Afterpay.client.post("/v2/payments/#{order_id}/void") do |req|
|
72
82
|
req.body = {
|
73
83
|
requestId: request_id,
|
@@ -77,7 +87,7 @@ module Afterpay
|
|
77
87
|
new(request.body)
|
78
88
|
end
|
79
89
|
|
80
|
-
def self.update_shipping_courier(order_id:, shipped_at
|
90
|
+
def self.update_shipping_courier(order_id:, shipped_at: nil, name: nil, tracking: nil, priority: nil)
|
81
91
|
request = Afterpay.client.put("/v2/payments/#{order_id}/courier") do |req|
|
82
92
|
req.body = {
|
83
93
|
shippedAt: shipped_at,
|
@@ -140,8 +150,7 @@ module Afterpay
|
|
140
150
|
# rubocop:disable Metrics/ParameterLists
|
141
151
|
|
142
152
|
# This endpoint retrieves a collection of payments along with their order details.
|
143
|
-
def self.list_payments(
|
144
|
-
merchant_ref:, statuses:, order_by:, asc:)
|
153
|
+
def self.list_payments(tokens:, ids:, merchant_ref:, statuses:, to_created_date: nil, from_created_date: nil, limit: nil, offset: nil, order_by: nil, asc: nil)
|
145
154
|
url = "/v2/payments?"
|
146
155
|
url += "toCreatedDate=#{to_created_date.gsub('+', '%2b')}" if to_created_date
|
147
156
|
url += "&fromCreatedDate=#{from_created_date.gsub('+', '%2b')}" if from_created_date
|
@@ -4,13 +4,27 @@ module Afterpay
|
|
4
4
|
class PaymentEvent
|
5
5
|
attr_accessor :id, :created, :expires, :type, :amount, :payment_event_merchant_reference
|
6
6
|
|
7
|
-
def initialize(attributes)
|
8
|
-
@id = attributes[:id]
|
9
|
-
@created = attributes[:created]
|
10
|
-
@expires = attributes[:expires]
|
11
|
-
@type = attributes[:
|
12
|
-
@amount =
|
13
|
-
@payment_event_merchant_reference = attributes[:
|
7
|
+
def initialize(attributes = {})
|
8
|
+
@id = attributes[:id] || ""
|
9
|
+
@created = attributes[:created] || ""
|
10
|
+
@expires = attributes[:expires] || ""
|
11
|
+
@type = attributes[:type] || ""
|
12
|
+
@amount = attributes[:amount] || Money.from_amount(0)
|
13
|
+
@payment_event_merchant_reference = attributes[:payment_event_merchant_reference] || ""
|
14
|
+
end
|
15
|
+
|
16
|
+
# Builds PaymentEvent from response
|
17
|
+
def self.from_response(response)
|
18
|
+
return nil if response.nil?
|
19
|
+
|
20
|
+
new(
|
21
|
+
id: response[:id],
|
22
|
+
created: response[:created],
|
23
|
+
expires: response[:expires],
|
24
|
+
type: response[:type],
|
25
|
+
amount: Utils::Money.from_response(response[:amount]),
|
26
|
+
payment_event_merchant_reference: response[:paymentEventMerchantReference]
|
27
|
+
)
|
14
28
|
end
|
15
29
|
end
|
16
30
|
end
|
data/lib/afterpay/refund.rb
CHANGED
@@ -5,18 +5,24 @@ module Afterpay
|
|
5
5
|
attr_accessor :request_id, :amount, :merchant_reference, :refund_id, :refunded_at,
|
6
6
|
:refund_merchant_reference, :error
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
@
|
13
|
-
@
|
14
|
-
@
|
15
|
-
@
|
8
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
9
|
+
# rubocop:disable Metrics/PerceivedComplexity
|
10
|
+
|
11
|
+
def initialize(attributes = {})
|
12
|
+
@request_id = attributes[:request_id] || ""
|
13
|
+
@amount = attributes[:amount] || Money.from_amount(0)
|
14
|
+
@merchant_reference = attributes[:merchant_reference] || ""
|
15
|
+
@refund_id = attributes[:refund_id] || ""
|
16
|
+
@refunded_at = attributes[:refunded_at] || ""
|
17
|
+
@refund_merchant_reference = attributes[:refund_merchant_reference] || ""
|
18
|
+
@error = Error.new(attributes[:error]) if attributes[:error] && attributes[:error][:errorId]
|
16
19
|
end
|
17
20
|
|
18
|
-
|
19
|
-
|
21
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
22
|
+
# rubocop:enable Metrics/PerceivedComplexity
|
23
|
+
|
24
|
+
def self.execute(order_id:, amount:, request_id: nil, merchant_reference: nil,
|
25
|
+
refund_merchant_reference: nil)
|
20
26
|
request = Afterpay.client.post("/v2/payments/#{order_id}/refund") do |req|
|
21
27
|
req.body = {
|
22
28
|
requestId: request_id,
|
@@ -25,7 +31,26 @@ module Afterpay
|
|
25
31
|
refundMerchantReference: refund_merchant_reference
|
26
32
|
}
|
27
33
|
end
|
28
|
-
|
34
|
+
from_response(request.body)
|
35
|
+
end
|
36
|
+
|
37
|
+
def success?
|
38
|
+
@error.nil?
|
39
|
+
end
|
40
|
+
|
41
|
+
# Builds Refund from response
|
42
|
+
def self.from_response(response)
|
43
|
+
return nil if response.nil?
|
44
|
+
|
45
|
+
new(
|
46
|
+
request_id: response[:requestId],
|
47
|
+
amount: Utils::Money.from_response(response[:amount]),
|
48
|
+
merchant_reference: response[:merchantReference],
|
49
|
+
refund_id: response[:refundId],
|
50
|
+
refunded_at: response[:refundedAt],
|
51
|
+
refund_merchant_reference: response[:refundMerchantReference],
|
52
|
+
error: response
|
53
|
+
)
|
29
54
|
end
|
30
55
|
end
|
31
56
|
end
|
@@ -4,11 +4,24 @@ module Afterpay
|
|
4
4
|
class ShippingCourier
|
5
5
|
attr_accessor :shipped_at, :name, :tracking, :priority
|
6
6
|
|
7
|
-
def initialize(
|
8
|
-
@shipped_at = shipped_at
|
9
|
-
@name = name
|
10
|
-
@tracking = tracking
|
11
|
-
@priority = priority
|
7
|
+
def initialize(attributes = {})
|
8
|
+
@shipped_at = attributes[:shipped_at] || ""
|
9
|
+
@name = attributes[:name] || ""
|
10
|
+
@tracking = attributes[:tracking] || ""
|
11
|
+
@priority = attributes[:priority] || ""
|
12
|
+
end
|
13
|
+
|
14
|
+
# Builds ShippingCourier from response
|
15
|
+
def self.from_response(response)
|
16
|
+
return nil if response.nil?
|
17
|
+
|
18
|
+
new(
|
19
|
+
shipped_at: response[:shippedAt],
|
20
|
+
name: response[:name],
|
21
|
+
tracking: response[:tracking],
|
22
|
+
priority: response[:priority],
|
23
|
+
error: Error.new(response)
|
24
|
+
)
|
12
25
|
end
|
13
26
|
end
|
14
27
|
end
|
data/lib/afterpay/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: afterpay-sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sachin Saxena
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-08-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -92,6 +92,20 @@ dependencies:
|
|
92
92
|
- - "~>"
|
93
93
|
- !ruby/object:Gem::Version
|
94
94
|
version: '3.0'
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: rubocop
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - "~>"
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '1.7'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - "~>"
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '1.7'
|
95
109
|
- !ruby/object:Gem::Dependency
|
96
110
|
name: faraday
|
97
111
|
requirement: !ruby/object:Gem::Requirement
|
@@ -153,12 +167,14 @@ executables: []
|
|
153
167
|
extensions: []
|
154
168
|
extra_rdoc_files: []
|
155
169
|
files:
|
170
|
+
- ".circleci/config.yml"
|
156
171
|
- ".env.sample"
|
157
172
|
- ".github/workflows/gempush.yml"
|
158
173
|
- ".gitignore"
|
159
174
|
- ".rspec"
|
160
175
|
- ".rubocop.yml"
|
161
176
|
- ".travis.yml"
|
177
|
+
- CHANGELOG.md
|
162
178
|
- CODE_OF_CONDUCT.md
|
163
179
|
- Gemfile
|
164
180
|
- Gemfile.lock
|
@@ -208,7 +224,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
208
224
|
- !ruby/object:Gem::Version
|
209
225
|
version: '0'
|
210
226
|
requirements: []
|
211
|
-
rubygems_version: 3.
|
227
|
+
rubygems_version: 3.0.3
|
212
228
|
signing_key:
|
213
229
|
specification_version: 4
|
214
230
|
summary: Afterpay ruby wrapper
|