afterpay-ruby 0.1.2 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e9ccc8dfcbb33be10f1b7e80eabd69201a9394b2a84dffe15ee91d47f42c86e5
4
- data.tar.gz: 8c59641cfcf6f1920a580663a48031d87b2f18f583dde0464d8a6dba19a9a7ad
3
+ metadata.gz: 5ca1e1c47d6b509844aedbf008e7af90c6b04534fbf163cb526b70891dcfa8f0
4
+ data.tar.gz: '072138f089151b6adc36c88eb37267a2c14fb3adff566777ef6af5d8fe158392'
5
5
  SHA512:
6
- metadata.gz: 6fadbc3a2967b0e61682686c1e96cee187e40411c37d62a2174dc985f781c83eec4b8adad6cd8239dcdf114db7720acb8c76d842135857b01527c1c4ae76da63
7
- data.tar.gz: 5d3c3f60df1ef845890c64daf337222e58f701f9a48785e3a233f6c864761f171b11e8d4bf46c05f804775f2511f4e3ba19b8236f624ad1ea0c85307394d2105
6
+ metadata.gz: a6243f64a347561daabde5135449521dffee10fb1c3b1faff2f0a34156ffc53fa358bb32851dcd59b608c02f1a8bfd1843c332e9af2a5a5fd0fd123b69841c64
7
+ data.tar.gz: 2d561c95396fa24a42afa375748e8e61b8d3a03454d40ec82827a38f00762ad832ea4890812a91cee41f8e26a843e95c6465426aa4bf2314f781f6c0a4fabf38
data/Gemfile CHANGED
@@ -4,8 +4,8 @@ source "https://rubygems.org"
4
4
  gemspec
5
5
 
6
6
  group :test do
7
+ gem "coveralls", require: false
7
8
  gem "simplecov", require: false
8
9
  gem "vcr", "~> 4.0"
9
10
  gem "webmock", "~> 3.5", ">= 3.5.1"
10
- gem 'coveralls', require: false
11
11
  end
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- afterpay-ruby (0.1.1)
4
+ afterpay-ruby (0.1.3)
5
5
  faraday (>= 0.8, < 1.0)
6
6
  faraday_middleware (~> 0.13.1)
7
7
  money (>= 6.7.1, < 7.0.0)
@@ -33,9 +33,9 @@ GEM
33
33
  concurrent-ruby (~> 1.0)
34
34
  json (2.2.0)
35
35
  method_source (0.9.2)
36
- money (6.13.2)
36
+ money (6.13.3)
37
37
  i18n (>= 0.6.4, <= 2)
38
- multipart-post (2.0.0)
38
+ multipart-post (2.1.0)
39
39
  pry (0.12.2)
40
40
  coderay (~> 1.1.0)
41
41
  method_source (~> 0.9.0)
data/README.md CHANGED
@@ -53,7 +53,12 @@ order = Afterpay::Order.create(
53
53
  consumer: <Afterpay::Consumer>,
54
54
  items: [<Afterpay::Item>],
55
55
  success_url: <String>,
56
- cancel_url: <String>
56
+ cancel_url: <String>,
57
+ reference: <String>,
58
+ shipping: <Money | optional>,
59
+ discounts: [<Afterpay::Discount | optional>],
60
+ billing_address: <Afterpay::Address | optional>,
61
+ shipping_address: <Afterpay::Address | optional>,
57
62
  )
58
63
 
59
64
  # OR
@@ -127,6 +132,38 @@ Afterpay::Item.new(
127
132
  )
128
133
  ```
129
134
 
135
+ ### Discount Object
136
+
137
+ [api docs](https://docs.afterpay.com/au-online-api-v1.html#discount-object)
138
+
139
+ Discount Applied to the Order
140
+
141
+ ```ruby
142
+ Afterpay::Discount.new(
143
+ name: <String>,
144
+ amount: <Money>
145
+ )
146
+ ```
147
+
148
+ ### Address Object
149
+
150
+ [api docs](https://docs.afterpay.com/au-online-api-v1.html#contact-object)
151
+
152
+ Item holds the details of purchace per item.
153
+
154
+ ```ruby
155
+ Afterpay::Address.new(
156
+ name: <String>,
157
+ line_1: <String>,
158
+ line_2: <String | optional>,
159
+ suburb: <String | optional>,
160
+ state: <String>,
161
+ postcode: <String | Number>,
162
+ country: <String | optional>,
163
+ phone: <String>
164
+ )
165
+ ```
166
+
130
167
  ## Development
131
168
 
132
169
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -4,6 +4,11 @@ require "bundler"
4
4
  require "bundler/setup"
5
5
  require "afterpay"
6
6
 
7
+ begin
8
+ require_relative "../configure"
9
+ rescue LoadError
10
+ end
11
+
7
12
  # You can add fixtures and/or initialization code here to make experimenting
8
13
  # with your gem easier. You can also use a different console, if you like.
9
14
 
@@ -3,6 +3,8 @@
3
3
  require "dotenv"
4
4
  Dotenv.load
5
5
 
6
+ Money.default_currency = ENV["DEFAULT_CURRENCY"] || "AUD"
7
+
6
8
  Afterpay.configure do |config|
7
9
  config.app_id = ENV["APP_ID"]
8
10
  config.secret = ENV["SECRET"]
@@ -13,3 +15,5 @@ Afterpay.configure do |config|
13
15
  # Sets the environment for Afterpay
14
16
  # config.env = "sandbox" # :live
15
17
  end
18
+
19
+ Afterpay.config.freeze
@@ -9,6 +9,8 @@ require_relative "afterpay/item"
9
9
  require_relative "afterpay/order"
10
10
  require_relative "afterpay/payment"
11
11
  require_relative "afterpay/error"
12
+ require_relative "afterpay/discount"
13
+ require_relative "afterpay/address"
12
14
  require_relative "afterpay/money_util"
13
15
 
14
16
  module Afterpay
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Afterpay
4
+ class Address
5
+ attr_accessor :name, :line1, :line2, :suburb, :state, :postcode, :country, :phone
6
+
7
+ # Initializes an Order object
8
+ #
9
+ # @overload initialize(total:, items:, consumer:, success_url:, cancel_url:, payment_type:)
10
+ # @param name [String] The name
11
+ # @param line_1 [String] Address line 1
12
+ # @param line_2 [String] optional Address line 2
13
+ # @param suburb [String] optional Suburb
14
+ # @param state [String] State
15
+ # @param postcode [String] Postal code
16
+ # @param country [String] optional country Code
17
+ # @param phone [String|Number] The phone number
18
+ def initialize(attributes = {})
19
+ @name = attributes[:name]
20
+ @line1 = attributes[:line_1] || ""
21
+ @line2 = attributes[:line_2] || ""
22
+ @suburb = attributes[:suburb] || ""
23
+ @state = attributes[:state] || ""
24
+ @postcode = attributes[:postcode]
25
+ @country = attributes[:country] || "AU"
26
+ @phone = attributes[:phone]
27
+ end
28
+
29
+ def to_hash
30
+ {
31
+ name: name,
32
+ line1: line1,
33
+ suburb: suburb,
34
+ state: state,
35
+ postcode: postcode.to_s,
36
+ countryCode: country,
37
+ phoneNumber: phone.to_s
38
+ }
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Afterpay
4
+ class Discount
5
+ attr_accessor :name, :amount
6
+
7
+ def initialize(name:, amount:)
8
+ @name = name
9
+ @amount = amount
10
+ end
11
+
12
+ def to_hash
13
+ {
14
+ displayName: name,
15
+ amount: {
16
+ amount: amount.to_f,
17
+ currency: amount.currency.iso_code
18
+ }
19
+ }
20
+ end
21
+ end
22
+ end
@@ -16,17 +16,18 @@ module Afterpay
16
16
  :tax,
17
17
  :discounts,
18
18
  :billing,
19
- :shipping,
19
+ :shipping_address,
20
+ :billing_address,
20
21
  :merchant_reference
21
22
 
22
- # Finds Order from Afterpay API
23
- # @param token [String]
24
- # @return [Order]
25
- def self.find(token)
26
- request = Afterpay.client.get("/v1/orders/#{token}")
23
+ # Finds Order from Afterpay API
24
+ # @param token [String]
25
+ # @return [Order]
26
+ def self.find(token)
27
+ request = Afterpay.client.get("/v1/orders/#{token}")
27
28
 
28
- Order.from_response(request.body)
29
- end
29
+ Order.from_response(request.body)
30
+ end
30
31
 
31
32
  # Builds Order from response
32
33
  # @param response [Hash] response params from API
@@ -65,6 +66,10 @@ module Afterpay
65
66
  # @param success_url [String] the path to redirect on successful payment
66
67
  # @param cancel_url [String] the path to redirect on failed payment
67
68
  # @param payment_type [String] Payment type defaults to {Config#type}
69
+ # @param shipping [Money] optional the billing Address
70
+ # @param discounts [Array<Afterpay::Discount>] optional discounts
71
+ # @param billing_address [<Afterpay::Address>] optional the billing Address
72
+ # @param shipping_address [<Afterpay::Address>] optional the shipping Address
68
73
  def initialize(attributes = {})
69
74
  @attributes = OpenStruct.new(attributes)
70
75
  @attributes.payment_type ||= Afterpay.config.type
@@ -75,7 +80,7 @@ module Afterpay
75
80
 
76
81
  # Builds structure to API specs
77
82
  def to_hash
78
- {
83
+ data = {
79
84
  totalAmount: {
80
85
  amount: total.to_f,
81
86
  currency: total.currency.iso_code
@@ -86,11 +91,19 @@ module Afterpay
86
91
  redirectConfirmUrl: attributes.success_url,
87
92
  redirectCancelUrl: attributes.cancel_url
88
93
  },
89
- merchantReference: attributes.merchant_reference,
94
+ merchantReference: attributes.reference,
90
95
  taxAmount: attributes.tax,
91
- shippingAmount: attributes.shipping,
96
+ shippingAmount: {
97
+ amount: shipping.to_f,
98
+ currency: shipping.currency.iso_code
99
+ },
92
100
  paymentType: attributes.payment_type
93
101
  }
102
+
103
+ data[:discounts] = discounts.map(&:to_hash) if discounts
104
+ data[:billing] = billing_address.to_hash if billing_address
105
+ data[:shipping] = shipping_address.to_hash if shipping_address
106
+ data
94
107
  end
95
108
 
96
109
  # Sends the create request to Afterpay server
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Afterpay
4
- VERSION = "0.1.2".freeze
4
+ VERSION = "0.1.3".freeze
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: afterpay-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eli
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-04-24 00:00:00.000000000 Z
11
+ date: 2019-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -165,9 +165,11 @@ files:
165
165
  - configure.rb
166
166
  - lib/afterpay-ruby.rb
167
167
  - lib/afterpay.rb
168
+ - lib/afterpay/address.rb
168
169
  - lib/afterpay/client.rb
169
170
  - lib/afterpay/config.rb
170
171
  - lib/afterpay/consumer.rb
172
+ - lib/afterpay/discount.rb
171
173
  - lib/afterpay/error.rb
172
174
  - lib/afterpay/item.rb
173
175
  - lib/afterpay/money_util.rb