amazon_pay_sdk_ruby 2.0.2
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 +7 -0
- data/.gitignore +16 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +35 -0
- data/LICENSE.txt +21 -0
- data/README.md +478 -0
- data/Rakefile +6 -0
- data/amazon_pay_sdk_ruby.gemspec +41 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/amazon_pay/amazon_in_store_client.rb +53 -0
- data/lib/amazon_pay/amazon_pay_client.rb +85 -0
- data/lib/amazon_pay/amazon_web_store_client.rb +215 -0
- data/lib/amazon_pay/client_helper.rb +185 -0
- data/lib/amazon_pay/constants.rb +23 -0
- data/lib/amazon_pay/version.rb +3 -0
- data/lib/amazon_pay_sdk_ruby.rb +12 -0
- metadata +104 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a011e5f19615809e2f2c509db59e3bea54a2eb2f862b93b4543e748cbef47615
|
4
|
+
data.tar.gz: 9f536bd179c9f41dd8bcee724ab7ec7a6820dbe20377183bcdd1979221f2256a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: aa8002c583784b74bfcc6348f98637179596477f6272e8c6bc2cb6d0cb00ed841ad181bb790ac038a6aa3b8388167db34df58f0d4205a104e237951d6f5304f8
|
7
|
+
data.tar.gz: b31eb6a23d9a070163575e96b9314b57d4946929c69d900165dfc272ab1323dcafac7b1a24eba23813d008ffcd26401a341849cc59183a22b217155296d60e01
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -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 everistusolumese@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
data/Gemfile.lock
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
amazon_pay_sdk_ruby (2.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.4.4)
|
10
|
+
rake (10.5.0)
|
11
|
+
rspec (3.9.0)
|
12
|
+
rspec-core (~> 3.9.0)
|
13
|
+
rspec-expectations (~> 3.9.0)
|
14
|
+
rspec-mocks (~> 3.9.0)
|
15
|
+
rspec-core (3.9.2)
|
16
|
+
rspec-support (~> 3.9.3)
|
17
|
+
rspec-expectations (3.9.2)
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
+
rspec-support (~> 3.9.0)
|
20
|
+
rspec-mocks (3.9.1)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.9.0)
|
23
|
+
rspec-support (3.9.3)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
amazon_pay_sdk_ruby!
|
30
|
+
bundler (~> 1.17)
|
31
|
+
rake (~> 10.0)
|
32
|
+
rspec (~> 3.0)
|
33
|
+
|
34
|
+
BUNDLED WITH
|
35
|
+
1.17.3
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Everistus Olumese
|
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,478 @@
|
|
1
|
+
# Amazon Pay API SDK (Ruby)
|
2
|
+
|
3
|
+
[](https://badge.fury.io/rb/amazon_pay_sdk_ruby)
|
4
|
+
|
5
|
+
Amazon Pay Checkout v2 Integration
|
6
|
+
|
7
|
+
Please note the Amazon Pay API SDK can only be used for API calls to the pay-api.amazon.com|eu|jp endpoint.
|
8
|
+
|
9
|
+
If you need to make an Amazon Pay API call that uses the mws.amazonservices.com|jp or mws-eu.amazonservices.com endpoint, then you will need to use the original [Amazon Pay SDK (Ruby)](https://github.com/amzn/amazon-pay-sdk-ruby).
|
10
|
+
|
11
|
+
## Requirements
|
12
|
+
|
13
|
+
- Amazon Pay account: To register for Amazon Pay, go to https://pay.amazon.com, choose your region by selecting the flag icon in the upper right corner, and then click "Register".
|
14
|
+
- Ruby 2.5.3 or higher
|
15
|
+
|
16
|
+
## Installation
|
17
|
+
|
18
|
+
Add this line to your application's Gemfile:
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
gem 'amazon_pay_sdk_ruby'
|
22
|
+
```
|
23
|
+
|
24
|
+
And then execute:
|
25
|
+
|
26
|
+
$ bundle
|
27
|
+
|
28
|
+
Or install it yourself as:
|
29
|
+
|
30
|
+
$ gem install amazon_pay_sdk_ruby
|
31
|
+
|
32
|
+
## Public and Private Keys
|
33
|
+
|
34
|
+
MWS access keys, MWS secret keys, and MWS authorization tokens from previous MWS integrations cannot be used with this SDK.
|
35
|
+
|
36
|
+
You will need to generate your own public/private key pair to make API calls with this SDK.
|
37
|
+
|
38
|
+
In Windows 10 this can be done with ssh-keygen commands:
|
39
|
+
|
40
|
+
```
|
41
|
+
ssh-keygen -t rsa -b 2048 -f private.pem
|
42
|
+
ssh-keygen -f private.pem -e -m PKCS8 > public.pub
|
43
|
+
```
|
44
|
+
|
45
|
+
In Linux or macOS this can be done using openssl commands:
|
46
|
+
|
47
|
+
```
|
48
|
+
openssl genrsa -out private.pem 2048
|
49
|
+
openssl rsa -in private.pem -pubout > public.pub
|
50
|
+
```
|
51
|
+
|
52
|
+
The first command above generates a private key and the second line uses the private key to generate a public key.
|
53
|
+
|
54
|
+
To associate the key with your account, follow the instructions here to
|
55
|
+
[Get your Public Key ID](http://amazonpaycheckoutintegrationguide.s3.amazonaws.com/amazon-pay-checkout/get-set-up-for-integration.html#4-get-your-public-key-id).
|
56
|
+
|
57
|
+
## Configuration
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
config = {
|
61
|
+
'public_Key_id': 'ABC123DEF456XYZ', # RSA Public Key ID (this is not the Merchant or Seller ID)
|
62
|
+
'private_key': File.read(File.expand_path('tst/private.pem', __dir__)), # Path to RSA Private Key (or a string representation)
|
63
|
+
'region': 'us', # Must be one of: 'us', 'eu', 'jp'
|
64
|
+
'sandbox': true # true (Sandbox) or false (Production) boolean
|
65
|
+
}
|
66
|
+
```
|
67
|
+
|
68
|
+
# Versioning
|
69
|
+
|
70
|
+
The pay-api.amazon.com|eu|jp endpoint uses versioning to allow future updates. The major version of this SDK will stay aligned with the API version of the endpoint.
|
71
|
+
|
72
|
+
If you have downloaded version 2.x.y of this SDK, version in below examples would be "v2".
|
73
|
+
|
74
|
+
# Convenience methods (Overview)
|
75
|
+
|
76
|
+
Make use of the built-in convenience methods to easily make API calls. Scroll down further to see example code snippets.
|
77
|
+
|
78
|
+
When using the convenience methods, the request payload will be signed using the provided private key, and a HTTPS request is made to the correct regional endpoint.
|
79
|
+
In the event of request throttling, the HTTPS call will be attempted up to three times
|
80
|
+
|
81
|
+
## Alexa Delivery Trackers API
|
82
|
+
|
83
|
+
Please note that your merchant account must be whitelisted to use the [Delivery Trackers API](https://developer.amazon.com/docs/amazon-pay-onetime/delivery-order-notifications.html).
|
84
|
+
|
85
|
+
- **delivery_trackers**(payload: nil, headers: nil) → POST to `#{version}/delivery_trackers`
|
86
|
+
|
87
|
+
## Authorization Tokens API
|
88
|
+
|
89
|
+
Please note that your solution provider account must have a pre-existing relationship (valid and active MWS authorization token) with the merchant account in order to use this method.
|
90
|
+
|
91
|
+
- **get_authorization_token**(mws_auth_token: nil, merchant_id: nil, headers: nil) → GET to `#{version}/authorizationTokens#{mws_auth_token}?merchantId=#{merchant_id}`
|
92
|
+
|
93
|
+
## Amazon Checkout v2 API
|
94
|
+
|
95
|
+
[Checkout v2 Integration Guide](https://amazonpaycheckoutintegrationguide.s3.amazonaws.com/amazon-pay-api-v2/introduction.html)
|
96
|
+
|
97
|
+
The headers field is not optional for create/POST calls below because it requires, at a minimum, the x-amz-pay-idempotency-key header:
|
98
|
+
|
99
|
+
```ruby
|
100
|
+
headers = {
|
101
|
+
'x-amz-pay-idempotency-key': SecureRandom.uuid.to_s.gsub(/-/, '')
|
102
|
+
}
|
103
|
+
```
|
104
|
+
|
105
|
+
### Amazon Checkout v2 Buyer Hash
|
106
|
+
|
107
|
+
- **get_buyer**(buyer_token: nil, headers: nil) → GET to `#{version}/buyer/{$buyerToken}`
|
108
|
+
|
109
|
+
### Checkout v2 CheckoutSession Hash
|
110
|
+
|
111
|
+
- **create_checkout_session**(payload: nil, headers: nil) → POST to `#{version}/checkoutSessions`
|
112
|
+
- **get_checkout_session**(checkout_session_id: nil, headers: nil) → GET to `#{version}/checkoutSessions/#{checkout_session_id}`
|
113
|
+
- **update_checkout_session**(checkout_session_id: nil, payload: nil, headers: nil) → PATCH to `#{version}/checkoutSessions#{checkout_session_id}`
|
114
|
+
- **complete_checkout_session**(checkout_session_id: nil, payload: nil, headers: nil) → POST to `#{version}/checkoutSessions#{checkout_session_id}/complete`
|
115
|
+
|
116
|
+
### Checkout v2 ChargePermission Hash
|
117
|
+
|
118
|
+
- **get_charge_permission**(charge_permission_id: nil, headers: nil) → GET to `#{version}/chargePermissions/#{charge_permission_id}`
|
119
|
+
- **update_charge_permission**(charge_permission_id: nil, payload: nil, headers: nil) → PATCH to `#{version}/chargePermissions#{charge_permission_id}`
|
120
|
+
- **close_charge_permission**(charge_permission_id: nil, payload: nil, headers: nil) → DELETE to `#{version}/chargePermissions#{charge_permission_id}/close`
|
121
|
+
|
122
|
+
### Checkout v2 Charge Hash
|
123
|
+
|
124
|
+
- **create_charge**(payload: nil, headers: nil) → POST to `#{version}/charges`
|
125
|
+
- **get_charge**(charge_id: nil, headers: nil) → GET to `#{version}/charges/#{charge_id}`
|
126
|
+
- **capture_charge**(charge_id: nil, payload: nil, headers: nil) → POST to `#{version}/charges/#{charge_id}/capture`
|
127
|
+
- **cancel_charge**(charge_id: nil, payload: nil, headers: nil) → DELETE to `#{version}/charges/#{charge_id}/cancel`
|
128
|
+
|
129
|
+
### Checkout v2 Refund Hash
|
130
|
+
|
131
|
+
- **create_refund**(payload: nil, headers: nil) → POST to `#{version}/refunds`
|
132
|
+
- **get_refund**(refund_id: nil, headers: nil) → GET to `#{version}/refunds/#{refund_id}`
|
133
|
+
|
134
|
+
## In-Store API
|
135
|
+
|
136
|
+
Please contact your Amazon Pay Account Manager before using the In-Store API calls in a Production environment to obtain a copy of the In-Store Integration Guide.
|
137
|
+
|
138
|
+
- **instore_merchant_scan**(payload: nil, headers: nil) → POST to `#{version}/in-store/merchant_scan`
|
139
|
+
- **instore_charge**(payload: nil, headers: nil) → POST to `#{version}/in-store/charge`
|
140
|
+
- **instore_refund**(payload: nil, headers: nil) → POST to `#{version}/in-store/refund`
|
141
|
+
|
142
|
+
# Using Convenience methods
|
143
|
+
|
144
|
+
Four quick steps are needed to make an API call:
|
145
|
+
|
146
|
+
Step 1. Construct a Client (using the previously defined Config Hash).
|
147
|
+
|
148
|
+
```ruby
|
149
|
+
require 'amazon_pay_sdk_ruby'
|
150
|
+
|
151
|
+
client = AmazonPay::AmazonPayClient.new(config)
|
152
|
+
#-or-
|
153
|
+
client = AmazonPay::AmazonWebStoreClient.new(config)
|
154
|
+
#-or-
|
155
|
+
client = AmazonPay::AmazonInStoreClient.new(config)
|
156
|
+
```
|
157
|
+
|
158
|
+
Step 2. Generate the payload.
|
159
|
+
|
160
|
+
```ruby
|
161
|
+
payload = {
|
162
|
+
scanData: 'UKhrmatMeKdlfY6b',
|
163
|
+
scanReferenceId: SecureRandom.uuid.to_s.gsub(/-/, ''),
|
164
|
+
merchantCOE: 'US',
|
165
|
+
ledgerCurrency: 'USD',
|
166
|
+
chargeTotal: {
|
167
|
+
currencyCode: 'USD',
|
168
|
+
amount: '2.00'
|
169
|
+
},
|
170
|
+
storeLocation: {
|
171
|
+
countryCode: 'US'
|
172
|
+
},
|
173
|
+
metadata: {
|
174
|
+
merchantNote: 'Merchant Name',
|
175
|
+
customInformation: 'in-store Software Purchase',
|
176
|
+
communicationContext: {
|
177
|
+
merchantStoreName: 'Store Name',
|
178
|
+
merchantOrderId: '789123'
|
179
|
+
}
|
180
|
+
}
|
181
|
+
}
|
182
|
+
```
|
183
|
+
|
184
|
+
Step 3. Execute the call.
|
185
|
+
|
186
|
+
```ruby
|
187
|
+
response = client.merchant_scan(payload: payload)
|
188
|
+
```
|
189
|
+
|
190
|
+
If you are a Solution Provider and need to make an API call on behalf of a different merchant account, you will need to pass along an extra authentication token parameter into the API call.
|
191
|
+
|
192
|
+
```ruby
|
193
|
+
test_headers = {
|
194
|
+
'x-amz-pay-authtoken': 'other_merchant_super_secret_token'
|
195
|
+
}
|
196
|
+
response = client.merchant_scan(payload: payload, headers: test_headers)
|
197
|
+
```
|
198
|
+
|
199
|
+
# Convenience methods Code Samples
|
200
|
+
|
201
|
+
## Alexa Delivery Notifications
|
202
|
+
|
203
|
+
```ruby
|
204
|
+
require 'amazon_pay_sdk_ruby'
|
205
|
+
|
206
|
+
config = {
|
207
|
+
public_key_id: 'ABC123DEF456XYZ',
|
208
|
+
private_key: File.read(File.expand_path('tst/private.pem', __dir__)),
|
209
|
+
region: 'us',
|
210
|
+
sandbox: true
|
211
|
+
}
|
212
|
+
|
213
|
+
payload = {
|
214
|
+
amazonOrderReferenceId: 'P00-0000000-0000000',
|
215
|
+
deliveryDetails: [{
|
216
|
+
trackingNumber: '1Z999AA10123456789',
|
217
|
+
carrierCode: 'UPS'
|
218
|
+
}]
|
219
|
+
}
|
220
|
+
|
221
|
+
client = AmazonPay::AmazonPayClient.new(config)
|
222
|
+
response = client.delivery_trackers(payload: payload)
|
223
|
+
```
|
224
|
+
|
225
|
+
## Checkout v2 - Create Checkout Session
|
226
|
+
|
227
|
+
```ruby
|
228
|
+
require 'amazon_pay_sdk_ruby'
|
229
|
+
|
230
|
+
config = {
|
231
|
+
public_key_id: 'ABC123DEF456XYZ',
|
232
|
+
private_key: File.read(File.expand_path('tst/private.pem', __dir__)),
|
233
|
+
region: 'us',
|
234
|
+
sandbox: true
|
235
|
+
}
|
236
|
+
|
237
|
+
payload = {
|
238
|
+
webCheckoutDetails: {
|
239
|
+
checkoutReviewReturnUrl: 'https://localhost/store/checkoutReview',
|
240
|
+
checkoutResultReturnUrl: 'https://localhost/store/checkoutReturn'
|
241
|
+
},
|
242
|
+
storeId: 'amzn1.application-oa2-client.5cc4962582fd4025a2962fc5350582d9' # Enter Client ID
|
243
|
+
}
|
244
|
+
headers = {
|
245
|
+
'x-amz-pay-idempotency-key': SecureRandom.uuid.to_s.gsub(/-/, '')
|
246
|
+
}
|
247
|
+
|
248
|
+
client = AmazonPay::AmazonWebStoreClient.new(config)
|
249
|
+
response = client.create_checkout_session(payload: payload, headers: headers)
|
250
|
+
```
|
251
|
+
|
252
|
+
## Checkout v2 - Get Checkout Session
|
253
|
+
|
254
|
+
```ruby
|
255
|
+
require 'amazon_pay_sdk_ruby'
|
256
|
+
|
257
|
+
config = {
|
258
|
+
public_key_id: 'ABC123DEF456XYZ',
|
259
|
+
private_key: File.read(File.expand_path('tst/private.pem', __dir__)),
|
260
|
+
region: 'us',
|
261
|
+
sandbox: true
|
262
|
+
}
|
263
|
+
|
264
|
+
headers = {
|
265
|
+
'x-amz-pay-idempotency-key': SecureRandom.uuid.to_s.gsub(/-/, '')
|
266
|
+
}
|
267
|
+
|
268
|
+
checkout_session_id = '00000000-0000-0000-0000-000000000000'
|
269
|
+
client = AmazonPay::AmazonWebStoreClient.new(config)
|
270
|
+
response = client.get_checkout_session(checkout_session_id: checkout_session_id, headers: headers)
|
271
|
+
```
|
272
|
+
|
273
|
+
## Checkout v2 - Update Checkout Session
|
274
|
+
|
275
|
+
```ruby
|
276
|
+
require 'amazon_pay_sdk_ruby'
|
277
|
+
|
278
|
+
config = {
|
279
|
+
public_key_id: 'ABC123DEF456XYZ',
|
280
|
+
private_key: File.read(File.expand_path('tst/private.pem', __dir__)),
|
281
|
+
region: 'us',
|
282
|
+
sandbox: true
|
283
|
+
}
|
284
|
+
|
285
|
+
payload = {
|
286
|
+
webCheckoutDetails: {
|
287
|
+
checkoutResultReturnUrl: 'https://localhost/store/checkoutReturn'
|
288
|
+
},
|
289
|
+
paymentDetails: {
|
290
|
+
paymentIntent: 'Confirm',
|
291
|
+
canHandlePendingAuthorization: false,
|
292
|
+
chargeAmount: {
|
293
|
+
amount: 50,
|
294
|
+
currencyCode: 'USD'
|
295
|
+
}
|
296
|
+
},
|
297
|
+
merchantMetadata: {
|
298
|
+
merchantReferenceId: SecureRandom.uuid.to_s.gsub(/-/, ''),
|
299
|
+
merchantStoreName: 'AmazonTestStoreFront',
|
300
|
+
noteToBuyer: 'merchantNoteForBuyer',
|
301
|
+
customInformation: ''
|
302
|
+
}
|
303
|
+
}
|
304
|
+
|
305
|
+
checkout_session_id = '00000000-0000-0000-0000-000000000000'
|
306
|
+
client = AmazonPay::AmazonWebStoreClient.new(config)
|
307
|
+
response = client.updateCheckoutSession(checkout_session_id: checkout_session_id, payload: payload)
|
308
|
+
```
|
309
|
+
|
310
|
+
## Checkout v2 - Capture Charge
|
311
|
+
|
312
|
+
```ruby
|
313
|
+
require 'amazon_pay_sdk_ruby'
|
314
|
+
|
315
|
+
config = {
|
316
|
+
public_key_id: 'ABC123DEF456XYZ',
|
317
|
+
private_key: File.read(File.expand_path('tst/private.pem', __dir__)),
|
318
|
+
region: 'us',
|
319
|
+
sandbox: true
|
320
|
+
}
|
321
|
+
|
322
|
+
payload = {
|
323
|
+
captureAmount: {
|
324
|
+
amount: '10.00',
|
325
|
+
currencyCode: 'USD'
|
326
|
+
},
|
327
|
+
softDescriptor: 'AMZN'
|
328
|
+
}
|
329
|
+
headers = {
|
330
|
+
'x-amz-pay-idempotency-key': SecureRandom.uuid.to_s.gsub(/-/, '')
|
331
|
+
}
|
332
|
+
|
333
|
+
charge_id = 'S01-0000000-0000000-C000000'
|
334
|
+
client = AmazonPay::AmazonWebStoreClient.new(config)
|
335
|
+
response = client.capture_charge(charge_id: charge_id, payload: payload, headers: headers)
|
336
|
+
```
|
337
|
+
|
338
|
+
## In Store MerchantScan
|
339
|
+
|
340
|
+
```ruby
|
341
|
+
payload = {
|
342
|
+
scanData: '[scanData]',
|
343
|
+
scanReferenceId: '[scanReferenceId]',
|
344
|
+
merchantCOE: 'US',
|
345
|
+
ledgerCurrency: 'USD'
|
346
|
+
}
|
347
|
+
|
348
|
+
response = client.merchant_scan(payload: payload)
|
349
|
+
merchant_scan_charge_permission_id = response[:charge_permission_id]
|
350
|
+
```
|
351
|
+
|
352
|
+
## Generate Button Signature
|
353
|
+
|
354
|
+
The signatures generated by this helper method are only valid for the Checkout v2 front-end buttons. Unlike API signing, no timestamps are involved, so the result of this method can be considered a static signature that can safely be placed in your website source files and used repeatedly (as long as your payload does not change).
|
355
|
+
|
356
|
+
Example call to generate_button_signature method:
|
357
|
+
|
358
|
+
```ruby
|
359
|
+
require 'amazon_pay_sdk_ruby'
|
360
|
+
|
361
|
+
config = {
|
362
|
+
public_key_id: 'ABC123DEF456XYZ',
|
363
|
+
private_key: File.read(File.expand_path('tst/private.pem', __dir__)),
|
364
|
+
region: 'us',
|
365
|
+
sandbox: true
|
366
|
+
}
|
367
|
+
|
368
|
+
client = AmazonPay::AmazonPayClient.new(config)
|
369
|
+
payload = {
|
370
|
+
webCheckoutDetails: {
|
371
|
+
checkoutReviewReturnUrl: 'https://localhosttst/checkoutReview.html',
|
372
|
+
checkoutResultReturnUrl: 'https://localhosttst/checkoutResult.html'
|
373
|
+
},
|
374
|
+
storeId: 'amzn1.application-oa2-client.xxxxx'
|
375
|
+
}
|
376
|
+
signature = client.generate_button_signature(payload: payload)
|
377
|
+
```
|
378
|
+
|
379
|
+
## Manual Signing (Advanced Use-Cases Only)
|
380
|
+
|
381
|
+
This SDK provides the ability to help you manually sign your API requests if you want to use your own code for sending the HTTPS request over the Internet.
|
382
|
+
|
383
|
+
Example call to api_call method with values:
|
384
|
+
|
385
|
+
```ruby
|
386
|
+
/** API to process a request
|
387
|
+
* - Makes an API Call using the specified options.
|
388
|
+
* @param {Hash} options - The options to make the API Call
|
389
|
+
* @param {String} options.method - The HTTP request method
|
390
|
+
* @param {String} options.url_fragment - The URI for the API Call
|
391
|
+
* @param {String} [options.payload=nil] - The payload for the API Call
|
392
|
+
* @param {String} [options.headers=nil] - The headers for the API Call
|
393
|
+
```
|
394
|
+
|
395
|
+
Example request method:
|
396
|
+
|
397
|
+
```ruby
|
398
|
+
options = {
|
399
|
+
method: 'POST',
|
400
|
+
url_fragment: '#{version}/in-store/merchant_scan',
|
401
|
+
payload = {
|
402
|
+
scanData: 'UKhrmatMeKdlfY6b',
|
403
|
+
scanReferenceId: '0b8fb271-2ae2-49a5-b35d4',
|
404
|
+
merchantCOE: 'US',
|
405
|
+
ledgerCurrency: 'USD',
|
406
|
+
chargeTotal: {
|
407
|
+
currencyCode: 'USD',
|
408
|
+
amount: '2.00'
|
409
|
+
},
|
410
|
+
storeLocation: {
|
411
|
+
countryCode: 'US'
|
412
|
+
},
|
413
|
+
metadata: {
|
414
|
+
merchantNote: 'Merchant Name',
|
415
|
+
customInformation: 'in-store Software Purchase',
|
416
|
+
communicationContext: {
|
417
|
+
merchantStoreName: 'Store Name',
|
418
|
+
merchantOrderId: '789123'
|
419
|
+
}
|
420
|
+
}
|
421
|
+
}
|
422
|
+
}
|
423
|
+
|
424
|
+
client = AmazonPay::AmazonInStoreClient.new(config)
|
425
|
+
signed_headers = client.api_call(options: options)
|
426
|
+
```
|
427
|
+
|
428
|
+
Example call to get_signed_headers method with values:
|
429
|
+
(This will only be used if you don't use api_call and want to create your own custom headers.)
|
430
|
+
|
431
|
+
```ruby
|
432
|
+
/** Signs the request headers
|
433
|
+
* - Signs the request provided and returns the signed headers Hash.
|
434
|
+
* @param {Hash} options - The options to make the API Call
|
435
|
+
* @param {String} options.method - The HTTP request method
|
436
|
+
* @param {String} options.url_fragment - The URI for the API Call
|
437
|
+
* @param {String} [options.payload=nil] - The payload for the API Call
|
438
|
+
* @param {String} [options.headers=nil] - The headers for the API Call
|
439
|
+
**/
|
440
|
+
```
|
441
|
+
|
442
|
+
Example request method:
|
443
|
+
|
444
|
+
```ruby
|
445
|
+
options = {
|
446
|
+
method: 'POST',
|
447
|
+
url_fragment: '#{version}/in-store/merchant_scan',
|
448
|
+
payload = {
|
449
|
+
scanData: 'UKhrmatMeKdlfY6b',
|
450
|
+
scanReferenceId: '0b8fb271-2ae2-49a5-b35d4',
|
451
|
+
merchantCOE: 'US',
|
452
|
+
ledgerCurrency: 'USD',
|
453
|
+
chargeTotal: {
|
454
|
+
currencyCode: 'USD',
|
455
|
+
amount: '2.00'
|
456
|
+
},
|
457
|
+
storeLocation: {
|
458
|
+
countryCode: 'US'
|
459
|
+
},
|
460
|
+
metadata: {
|
461
|
+
merchantNote: 'Merchant Name',
|
462
|
+
customInformation: 'in-store Software Purchase',
|
463
|
+
communicationContext: {
|
464
|
+
merchantStoreName: 'Store Name',
|
465
|
+
merchantOrderId: '789123'
|
466
|
+
}
|
467
|
+
}
|
468
|
+
},
|
469
|
+
headers: {
|
470
|
+
'Accept': 'application/rubyon',
|
471
|
+
'Content-Type': 'application/rubyon'
|
472
|
+
'X-Amz-Pay-Region': 'us'
|
473
|
+
}
|
474
|
+
}
|
475
|
+
|
476
|
+
client = AmazonPay::AmazonPayClient.new(config)
|
477
|
+
signed_headers = client.get_signed_headers(options: options)
|
478
|
+
```
|