afterpay-sdk 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -0
- data/Gemfile.lock +2 -2
- data/README.md +5 -5
- 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 +28 -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 +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6394dc3cf60aa29c10d0ad90f48515bfb680ce0fe98d835ccd681e72e78df967
|
4
|
+
data.tar.gz: 4f52e6c827219307155e2fe098e339e9b3b6406b357d951ff4aa531e16142727
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0b586120bd8bdd18b4237ca64d16f95a86f6b33b0e7a7f5c0a1d0af417adb1ca35cb68e3ead7e550303ac0aafe16fc355243c08c6eceb4e9e40de1d00f0d54a
|
7
|
+
data.tar.gz: d09988e100a89972b89344bb3f0fd1824e02974495117b5130d542799d75ecb39fe0540635049aae02dac06305ba9d9abff0b8bf1faa51cf5183c54ba3a4d5a7
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,17 @@
|
|
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
|
+
|
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.1)
|
5
5
|
faraday (>= 0.8, < 1.0)
|
6
6
|
faraday_middleware (~> 0.13.1)
|
7
7
|
money (>= 6.7.1, < 7.0.0)
|
@@ -12,7 +12,7 @@ GEM
|
|
12
12
|
addressable (2.6.0)
|
13
13
|
public_suffix (>= 2.0.2, < 4.0)
|
14
14
|
coderay (1.1.2)
|
15
|
-
concurrent-ruby (1.1.
|
15
|
+
concurrent-ruby (1.1.9)
|
16
16
|
coveralls (0.8.22)
|
17
17
|
json (>= 1.8, < 3)
|
18
18
|
simplecov (~> 0.16.1)
|
data/README.md
CHANGED
@@ -46,9 +46,9 @@ end
|
|
46
46
|
|
47
47
|
### Creating an Order
|
48
48
|
|
49
|
-
[api docs](https://
|
49
|
+
[api docs](https://developers.afterpay.com/afterpay-online/reference#checkouts)
|
50
50
|
|
51
|
-
Order accepts a [Consumer](YourMechanic/afterpay-sdk#consumer-object) and an array of [Item](YourMechanic/afterpay-sdk#item-object) object which are required.
|
51
|
+
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
52
|
|
53
53
|
```ruby
|
54
54
|
order = Afterpay::Order.create(
|
@@ -57,7 +57,7 @@ order = Afterpay::Order.create(
|
|
57
57
|
items: [<Afterpay::Item>],
|
58
58
|
success_url: <String>,
|
59
59
|
cancel_url: <String>,
|
60
|
-
|
60
|
+
merchant_reference: <String>,
|
61
61
|
tax: <Money>,
|
62
62
|
shipping: <Money | optional>,
|
63
63
|
discounts: [<Afterpay::Discount | optional>],
|
@@ -94,7 +94,7 @@ order.error
|
|
94
94
|
```ruby
|
95
95
|
payment = Afterpay::Payment.execute(
|
96
96
|
token: token <String>,
|
97
|
-
|
97
|
+
merchant_reference: "checkout-1" <String>
|
98
98
|
)
|
99
99
|
=> <Afterpay::Payment ...>
|
100
100
|
|
@@ -115,7 +115,7 @@ For Auth
|
|
115
115
|
Afterpay::Payment.execute_auth(request_id: 'fjfwwwjfj090292920', token: '002.v4krg5qpii1tbp0kvr261rf3p1k5jfe2fin', merchant_reference: '100101382')
|
116
116
|
|
117
117
|
For executing deferred payment
|
118
|
-
Afterpay::Payment.execute_deferred_payment(request_id: 'ppjjjkjk',
|
118
|
+
Afterpay::Payment.execute_deferred_payment(request_id: 'ppjjjkjk', merchant_reference: '100101382', amount: mony, payment_event_merchant_reference: '', order_id: 100101524323)
|
119
119
|
```
|
120
120
|
|
121
121
|
### Void payment
|
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,22 +8,28 @@ 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
|
@@ -31,19 +37,19 @@ module Afterpay
|
|
31
37
|
# Executes the Payment
|
32
38
|
#
|
33
39
|
# @param token [String] the Order token
|
34
|
-
# @param
|
40
|
+
# @param merchant_reference [String] the merchant_reference for payment
|
35
41
|
# @return [Payment] the Payment object
|
36
|
-
def self.execute(token:,
|
42
|
+
def self.execute(token:, merchant_reference: nil)
|
37
43
|
request = Afterpay.client.post("/v2/payments/capture") do |req|
|
38
44
|
req.body = {
|
39
45
|
token: token,
|
40
|
-
|
46
|
+
merchantReference: merchant_reference
|
41
47
|
}
|
42
48
|
end
|
43
49
|
new(request.body)
|
44
50
|
end
|
45
51
|
|
46
|
-
def self.execute_auth(
|
52
|
+
def self.execute_auth(token:, request_id: nil, merchant_reference: nil)
|
47
53
|
request = Afterpay.client.post("/v2/payments/auth") do |req|
|
48
54
|
req.body = {
|
49
55
|
requestId: request_id,
|
@@ -54,12 +60,12 @@ module Afterpay
|
|
54
60
|
new(request.body)
|
55
61
|
end
|
56
62
|
|
57
|
-
def self.execute_deferred_payment(
|
58
|
-
payment_event_merchant_reference
|
63
|
+
def self.execute_deferred_payment(amount:, order_id:, request_id: nil, merchant_reference: nil,
|
64
|
+
payment_event_merchant_reference: nil)
|
59
65
|
request = Afterpay.client.post("/v2/payments/#{order_id}/capture") do |req|
|
60
66
|
req.body = {
|
61
67
|
requestId: request_id,
|
62
|
-
|
68
|
+
merchantReference: merchant_reference,
|
63
69
|
amount: Utils::Money.api_hash(amount),
|
64
70
|
paymentEventMerchantReference: payment_event_merchant_reference
|
65
71
|
}
|
@@ -67,7 +73,7 @@ module Afterpay
|
|
67
73
|
new(request.body)
|
68
74
|
end
|
69
75
|
|
70
|
-
def self.execute_void(
|
76
|
+
def self.execute_void(order_id:, amount:, request_id: nil)
|
71
77
|
request = Afterpay.client.post("/v2/payments/#{order_id}/void") do |req|
|
72
78
|
req.body = {
|
73
79
|
requestId: request_id,
|
@@ -77,7 +83,7 @@ module Afterpay
|
|
77
83
|
new(request.body)
|
78
84
|
end
|
79
85
|
|
80
|
-
def self.update_shipping_courier(order_id:, shipped_at
|
86
|
+
def self.update_shipping_courier(order_id:, shipped_at: nil, name: nil, tracking: nil, priority: nil)
|
81
87
|
request = Afterpay.client.put("/v2/payments/#{order_id}/courier") do |req|
|
82
88
|
req.body = {
|
83
89
|
shippedAt: shipped_at,
|
@@ -140,8 +146,7 @@ module Afterpay
|
|
140
146
|
# rubocop:disable Metrics/ParameterLists
|
141
147
|
|
142
148
|
# This endpoint retrieves a collection of payments along with their order details.
|
143
|
-
def self.list_payments(
|
144
|
-
merchant_ref:, statuses:, order_by:, asc:)
|
149
|
+
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
150
|
url = "/v2/payments?"
|
146
151
|
url += "toCreatedDate=#{to_created_date.gsub('+', '%2b')}" if to_created_date
|
147
152
|
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.1
|
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-06
|
11
|
+
date: 2021-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -159,6 +159,7 @@ files:
|
|
159
159
|
- ".rspec"
|
160
160
|
- ".rubocop.yml"
|
161
161
|
- ".travis.yml"
|
162
|
+
- CHANGELOG.md
|
162
163
|
- CODE_OF_CONDUCT.md
|
163
164
|
- Gemfile
|
164
165
|
- Gemfile.lock
|
@@ -208,7 +209,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
208
209
|
- !ruby/object:Gem::Version
|
209
210
|
version: '0'
|
210
211
|
requirements: []
|
211
|
-
rubygems_version: 3.
|
212
|
+
rubygems_version: 3.0.8
|
212
213
|
signing_key:
|
213
214
|
specification_version: 4
|
214
215
|
summary: Afterpay ruby wrapper
|