afterpay-sdk 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d11a93da08d6aef6124413f47bbdadc7a16a8b7bb0eefdc432b7550b722d5275
4
+ data.tar.gz: f85183189810df17af941f776e2a900802cbf3f1df66d5e49d9b8b018dc2ed63
5
+ SHA512:
6
+ metadata.gz: 33b5ada12c5ea764399ed5558329d0641daba8922e1636483fee3eb86ad315e8de013b3acfdd1427145a7e7f9f39b3333fd17e3afc4aa6dc58b4acb1587cfa68
7
+ data.tar.gz: d5277fc45fa4a21ecf3d686d5993cd3a035ebfb6bb1603ff99d58e1f10b08235e4626b5e8394e545700e015e7ace72604fac632ebd4400a10f730b30cd6c37dc
data/.env.sample ADDED
@@ -0,0 +1,2 @@
1
+ APP_ID=
2
+ SECRET=
@@ -0,0 +1,30 @@
1
+ name: Ruby Gem
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+ branches: [ master ]
8
+
9
+ jobs:
10
+ build:
11
+ name: Build + Publish
12
+ runs-on: ubuntu-latest
13
+
14
+ steps:
15
+ - uses: actions/checkout@v2
16
+ - name: Set up Ruby 2.6
17
+ uses: actions/setup-ruby@v1
18
+ with:
19
+ version: 2.6.x
20
+
21
+ - name: Publish to RubyGems
22
+ run: |
23
+ mkdir -p $HOME/.gem
24
+ touch $HOME/.gem/credentials
25
+ chmod 0600 $HOME/.gem/credentials
26
+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
27
+ gem build *.gemspec
28
+ gem push *.gem
29
+ env:
30
+ GEM_HOST_API_KEY: ${{secrets.RUBYGEMS_AUTH_TOKEN}}
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ .DS_Store
2
+ /.bundle/
3
+ /.yardoc
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
13
+ .env
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,33 @@
1
+ AllCops:
2
+ Exclude:
3
+ - "afterpay-sdk.gemspec"
4
+ - "bin/*"
5
+
6
+ Style/StringLiterals:
7
+ EnforcedStyle: double_quotes
8
+ Style/Documentation:
9
+ Enabled: false
10
+ Style/NumericLiterals:
11
+ Enabled: false
12
+ Style/FrozenStringLiteralComment:
13
+ EnforcedStyle: always
14
+ Exclude:
15
+ - "spec/**/*"
16
+ - "Gemfile"
17
+ - "Rakefile"
18
+
19
+ Metrics/BlockLength:
20
+ Exclude:
21
+ - "spec/**/*_spec.rb"
22
+ Metrics/LineLength:
23
+ Enabled: false
24
+ Metrics/AbcSize:
25
+ Enabled: false
26
+ Metrics/MethodLength:
27
+ Enabled: false
28
+
29
+ Naming/FileName:
30
+ Exclude:
31
+ - "lib/afterpay-sdk.rb"
32
+ Naming/VariableNumber:
33
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.2
7
+ - 2.6.1
8
+ - 2.5.1
9
+ - 2.3.3
10
+ before_install: gem install bundler -v 2.0.1
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at iamchoonggg@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in afterpay-sdk.gemspec
4
+ gemspec
5
+
6
+ group :test do
7
+ gem "coveralls", require: false
8
+ gem "simplecov", require: false
9
+ gem "vcr", "~> 4.0"
10
+ gem "webmock", "~> 3.5", ">= 3.5.1"
11
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,89 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ afterpay-sdk (2.0.0)
5
+ faraday (>= 0.8, < 1.0)
6
+ faraday_middleware (~> 0.13.1)
7
+ money (>= 6.7.1, < 7.0.0)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ addressable (2.6.0)
13
+ public_suffix (>= 2.0.2, < 4.0)
14
+ coderay (1.1.2)
15
+ concurrent-ruby (1.1.8)
16
+ coveralls (0.8.22)
17
+ json (>= 1.8, < 3)
18
+ simplecov (~> 0.16.1)
19
+ term-ansicolor (~> 1.3)
20
+ thor (~> 0.19.4)
21
+ tins (~> 1.6)
22
+ crack (0.4.3)
23
+ safe_yaml (~> 1.0.0)
24
+ diff-lcs (1.3)
25
+ docile (1.3.1)
26
+ dotenv (2.7.2)
27
+ faraday (0.17.4)
28
+ multipart-post (>= 1.2, < 3)
29
+ faraday_middleware (0.13.1)
30
+ faraday (>= 0.7.4, < 1.0)
31
+ hashdiff (0.3.8)
32
+ i18n (1.8.9)
33
+ concurrent-ruby (~> 1.0)
34
+ json (2.3.1)
35
+ method_source (0.9.2)
36
+ money (6.16.0)
37
+ i18n (>= 0.6.4, <= 2)
38
+ multipart-post (2.1.1)
39
+ pry (0.12.2)
40
+ coderay (~> 1.1.0)
41
+ method_source (~> 0.9.0)
42
+ public_suffix (3.0.3)
43
+ rake (12.3.3)
44
+ rspec (3.8.0)
45
+ rspec-core (~> 3.8.0)
46
+ rspec-expectations (~> 3.8.0)
47
+ rspec-mocks (~> 3.8.0)
48
+ rspec-core (3.8.0)
49
+ rspec-support (~> 3.8.0)
50
+ rspec-expectations (3.8.2)
51
+ diff-lcs (>= 1.2.0, < 2.0)
52
+ rspec-support (~> 3.8.0)
53
+ rspec-mocks (3.8.0)
54
+ diff-lcs (>= 1.2.0, < 2.0)
55
+ rspec-support (~> 3.8.0)
56
+ rspec-support (3.8.0)
57
+ safe_yaml (1.0.5)
58
+ simplecov (0.16.1)
59
+ docile (~> 1.1)
60
+ json (>= 1.8, < 3)
61
+ simplecov-html (~> 0.10.0)
62
+ simplecov-html (0.10.2)
63
+ term-ansicolor (1.7.1)
64
+ tins (~> 1.0)
65
+ thor (0.19.4)
66
+ tins (1.20.2)
67
+ vcr (4.0.0)
68
+ webmock (3.5.1)
69
+ addressable (>= 2.3.6)
70
+ crack (>= 0.3.2)
71
+ hashdiff
72
+
73
+ PLATFORMS
74
+ ruby
75
+
76
+ DEPENDENCIES
77
+ afterpay-sdk!
78
+ bundler (~> 2.0)
79
+ coveralls
80
+ dotenv (~> 2.2, >= 2.2.1)
81
+ pry
82
+ rake (~> 12.3, >= 12.3.3)
83
+ rspec (~> 3.0)
84
+ simplecov
85
+ vcr (~> 4.0)
86
+ webmock (~> 3.5, >= 3.5.1)
87
+
88
+ BUNDLED WITH
89
+ 2.2.11
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Elijah Goh Chong Hui
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,284 @@
1
+ # Afterpay Ruby
2
+
3
+ Based on the [API docs](https://developers.afterpay.com/afterpay-online/reference)
4
+
5
+ Afterpay Ruby is a Ruby wrapper for Afterpay API. It provides simple DSL and serialization to Afterpay's API attribute. This version supports the v2 version of Afterpay API.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'afterpay-sdk'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install afterpay-sdk
22
+
23
+ ## Usage
24
+
25
+ You need to configure Afterpay using your Merchant ID and secret.
26
+
27
+ For Rails, put this in your initializer.
28
+
29
+ ```ruby
30
+ Afterpay.configure do |config|
31
+ config.app_id = <app_id>
32
+ config.secret = <secret>
33
+
34
+ # Sets the environment for Afterpay
35
+ # defaults to sandbox
36
+ # config.env = "sandbox" # "live"
37
+
38
+ # Sets the user agent header for Afterpay requests
39
+ # Refer https://developers.afterpay.com/afterpay-online/reference#configuration
40
+ # config.user_agent_header = {pluginOrModuleOrClientLibrary}/{pluginVersion} ({platform}/{platformVersion}; Merchant/{merchantId}) { merchantUrl }
41
+ # Example
42
+ # config.user_agent_header = "Afterpay Module / 1.0.0 (rails/ 5.1.2; Merchant/#{ merchant_id }) #{ merchant_website_url }"
43
+
44
+ end
45
+ ```
46
+
47
+ ### Creating an Order
48
+
49
+ [api docs](https://YourMechanic/afterpay-sdk#create-checkout)
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.
52
+
53
+ ```ruby
54
+ order = Afterpay::Order.create(
55
+ total: <Money>,
56
+ consumer: <Afterpay::Consumer>,
57
+ items: [<Afterpay::Item>],
58
+ success_url: <String>,
59
+ cancel_url: <String>,
60
+ reference: <String>,
61
+ tax: <Money>,
62
+ shipping: <Money | optional>,
63
+ discounts: [<Afterpay::Discount | optional>],
64
+ billing_address: <Afterpay::Address | optional>,
65
+ shipping_address: <Afterpay::Address | optional>,
66
+ )
67
+
68
+ # OR
69
+
70
+ order = Afterpay::Order.new(
71
+ ...
72
+ )
73
+ order.create
74
+
75
+
76
+ order.success?
77
+ => true
78
+ order.token
79
+ => xxxxxxx
80
+
81
+ # Error
82
+
83
+ order.success?
84
+ => false
85
+ order.error
86
+ => Afterpay::Error:0x00007f8a63953888
87
+ @id="48da0bce49d39625",
88
+ @code="invalid_object",
89
+ @message="merchant.redirectConfirmUrl must be a valid URL, merchant.redirectConfirmUrl may not be empty" >
90
+ ```
91
+
92
+ ### Executing Payment
93
+
94
+ ```ruby
95
+ payment = Afterpay::Payment.execute(
96
+ token: token <String>,
97
+ reference: "checkout-1" <String>
98
+ )
99
+ => <Afterpay::Payment ...>
100
+
101
+ payment.success?
102
+ => true
103
+ payment.order
104
+ => <Afterpay::Order ...>
105
+ payment.status
106
+ => APPROVED
107
+ ```
108
+
109
+ ### Deferred Payment
110
+
111
+ ```ruby
112
+ mony = Money.from_amount(1000, "USD")
113
+
114
+ For Auth
115
+ Afterpay::Payment.execute_auth(request_id: 'fjfwwwjfj090292920', token: '002.v4krg5qpii1tbp0kvr261rf3p1k5jfe2fin', merchant_reference: '100101382')
116
+
117
+ For executing deferred payment
118
+ Afterpay::Payment.execute_deferred_payment(request_id: 'ppjjjkjk', reference: '100101382', amount: mony, payment_event_merchant_reference: '', order_id: 100101524323)
119
+ ```
120
+
121
+ ### Void payment
122
+
123
+ ```ruby
124
+ Afterpay::Payment.execute_void(request_id: 'ppjjjkjk', order_id: 'same_as_id_of_auth_output', amount: mony)
125
+ ```
126
+
127
+ ### Refund
128
+
129
+ ```ruby
130
+ Afterpay::Refund.execute(request_id: 'unique_id', order_id: 'order_id', amount: mony, merchant_reference: '100101382', refund_merchant_reference: '100101111')
131
+ ```
132
+
133
+ ### Update Shipping Courier
134
+
135
+ ```ruby
136
+ Afterpay::Payment.update_shipping_courier(order_id: valid_order_id,
137
+ shipped_at: DateTime.now.iso8601,
138
+ name: "Bludart",
139
+ tracking: "AWB129181",
140
+ priority: "EXPRESS")
141
+ ```
142
+
143
+ ### Get Payment By Order Id
144
+
145
+ This endpoint retrieves an individual payment along with its order details.
146
+
147
+ ```ruby
148
+ Afterpay::Payment.get_payment_by_order_id(order_id: valid_order_id)
149
+
150
+ ```
151
+
152
+ ### Get Payment By Token
153
+
154
+ This endpoint retrieves an individual payment along with its order details.
155
+
156
+ ```ruby
157
+ Afterpay::Payment.get_payment_by_token(token: valid_token)
158
+
159
+ ```
160
+
161
+ ### Update Payment by Order Id
162
+
163
+ This end point is for merchants that creates merchant side's order id after
164
+ AfterPay order id creation. The merchants should call immediately after the AfterPay order is
165
+ in order to properly update with their order id that can be tracked.
166
+
167
+ ```ruby
168
+ Afterpay::Payment.update_payment_by_order_id(order_id: valid_order_id,
169
+ merchant_reference: "new_merchant_order_id_1234")
170
+ ```
171
+
172
+ ### reverse_payment_by_token
173
+
174
+ This endpoint performs a reversal of the checkout that is used to initiate
175
+ the Afterpay payment process. This will cancel the order asynchronously as
176
+ soon as it is created without the need of an additional call to the void endpoint.
177
+ In order for a payment to be eligible, the order must be in an Auth-Approved or
178
+ Captured state and must be issued within 10 minutes of the order being created.
179
+ token paramater is the token of the checkout to be reversed (voided).
180
+
181
+ ```ruby
182
+ Afterpay::Payment.reverse_payment_by_token(token: valid_token)
183
+ ```
184
+
185
+ ### list_payments
186
+
187
+ This endpoint retrieves a collection of payments along with their order details.
188
+
189
+ ```ruby
190
+ Afterpay::Payment.list_payments(
191
+ to_created_date: nil,
192
+ from_created_date: nil, limit: 10, offset: 0,
193
+ tokens: [],
194
+ ids: ["100101533036"], merchant_ref: ["100101382"],
195
+ statuses: ["Approved"], order_by: "createdAt", asc: false
196
+ )
197
+ ```
198
+
199
+ ### Consumer Object
200
+
201
+ [api docs](https://developers.afterpay.com/afterpay-online/reference#consumer-object)
202
+
203
+ Consumer contains the details of the payee which will be serialized to API's format.
204
+
205
+ ```ruby
206
+ Afterpay::Consumer.new(
207
+ email: <String>,
208
+ phone: <String>,
209
+ first_name: <String>,
210
+ last_name: <String>,
211
+ )
212
+ ```
213
+
214
+ ### Item Object
215
+
216
+ [api docs](https://developers.afterpay.com/afterpay-online/reference#item-object)
217
+
218
+ Item holds the details of purchace per item.
219
+
220
+ ```ruby
221
+ Afterpay::Item.new(
222
+ name: <String>,
223
+ price: <Money>,
224
+ sku: <String | optional>,
225
+ quantity: <Number | defaults to 1>,
226
+ page_url: <String | optional>,
227
+ image_url: <String | optional>,
228
+ categories: [][],
229
+ estimatedShipmentDate: <String | optional>
230
+ )
231
+ ```
232
+
233
+ ### Discount Object
234
+
235
+ [api docs](https://developers.afterpay.com/afterpay-online/reference#discount-object)
236
+
237
+ Discount Applied to the Order
238
+
239
+ ```ruby
240
+ Afterpay::Discount.new(
241
+ name: <String>,
242
+ amount: <Money>
243
+ )
244
+ ```
245
+
246
+ ### Address Object
247
+
248
+ [api docs](https://developers.afterpay.com/afterpay-online/reference#contact-object)
249
+
250
+ Item holds the details of purchace per item.
251
+
252
+ ```ruby
253
+ Afterpay::Address.new(
254
+ name: <String>,
255
+ line_1: <String>,
256
+ line_2: <String | optional>,
257
+ area_1: <String | required | Limited to 128 characters>,
258
+ area_2: <String | optional | Limited to 128 characters>,
259
+ region: <String | required | Limited to 128 characters>,
260
+ postcode: <String | Number>,
261
+ country: <String | optional>,
262
+ phone: <String>
263
+ )
264
+ ```
265
+
266
+ ## Development
267
+
268
+ 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.
269
+
270
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
271
+
272
+ ## Contributing
273
+
274
+ Bug reports and pull requests are welcome on GitHub at https://github.com/YourMechanic/afterpay-sdk. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
275
+
276
+ You will need to copy `.env.sample` to `.env` for running Afterpay console. This will not be checked into git.
277
+
278
+ ## License
279
+
280
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
281
+
282
+ ## Code of Conduct
283
+
284
+ Everyone interacting in the Afterpay project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/afterpay-sdk/blob/master/CODE_OF_CONDUCT.md).