amazon-pay-api-sdk-ruby 1.0.0 → 1.1.0
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/README.md +402 -7
- data/lib/amazon_pay/client.rb +167 -0
- data/lib/amazon_pay/constants.rb +9 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff292f2eaf06b442175de16106fb31f54042337f11af7653609bf436eb34133a
|
4
|
+
data.tar.gz: b752565c83f486c960878d54fd204c6f70c543544d5574a5f820c5210e8f857d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f45eaed130252eb5e06094fefd1cbc16d923a14c5248250118264ab29db0992bfc2c0bd3d4c820f7019aa2bae43241f3cdc0b5f148500724af32cbef454827d8
|
7
|
+
data.tar.gz: 8e867a51a1ffacd9eaee7c39c4217d0466dc3b651be3a89e71b0b8f0899696748be58cc6390d5b53a4417ede4368968919b9cc38ce662bcc1cabe8f0c47f873c
|
data/README.md
CHANGED
@@ -135,7 +135,7 @@ createMerchantAccountPayload = {
|
|
135
135
|
"storeName": "ABC ABC",
|
136
136
|
"privacyPolicyUrl": "http://www.abc.com/privacy",
|
137
137
|
"storeStatus": {
|
138
|
-
"state": "
|
138
|
+
"state": "ACTIVE",
|
139
139
|
"reasonCode": nil
|
140
140
|
}
|
141
141
|
},
|
@@ -146,11 +146,7 @@ createMerchantAccountPayload = {
|
|
146
146
|
}
|
147
147
|
}
|
148
148
|
|
149
|
-
|
150
|
-
"x-amz-pay-Idempotency-Key": "idempotency-key"
|
151
|
-
}
|
152
|
-
|
153
|
-
response = client.create_merchant_account(createMerchantAccountPayload, headers: createMerchantAccountHeader)
|
149
|
+
response = client.create_merchant_account(createMerchantAccountPayload, headers: {})
|
154
150
|
if response.code.to_i == 201 || response.code.to_i == 200
|
155
151
|
puts "Create Merchant Account API Response:"
|
156
152
|
puts response.body
|
@@ -183,7 +179,9 @@ updateMerchantAccountPayload = {
|
|
183
179
|
}
|
184
180
|
}
|
185
181
|
|
186
|
-
updateMerchantAccountHeader = {
|
182
|
+
updateMerchantAccountHeader = {
|
183
|
+
"x-amz-pay-authToken" : "AUTH_TOKEN"
|
184
|
+
}
|
187
185
|
|
188
186
|
response = client.update_merchant_account('XXXXXXXXX', updateMerchantAccountPayload, headers: updateMerchantAccountHeader)
|
189
187
|
if response.code.to_i == 200
|
@@ -215,4 +213,401 @@ else
|
|
215
213
|
puts "Status: #{response.code}"
|
216
214
|
puts response.body
|
217
215
|
end
|
216
|
+
```
|
217
|
+
|
218
|
+
### Generate Button Signature
|
219
|
+
|
220
|
+
```ruby
|
221
|
+
def button_payload = {
|
222
|
+
"webCheckoutDetails": {
|
223
|
+
"checkoutReviewReturnUrl": "https://a.com/merchant-review-page"
|
224
|
+
},
|
225
|
+
"storeId": "amzn1.application-oa2-client.xxxxxxxxxxxx",
|
226
|
+
"scopes": ["name", "email", "phoneNumber", "billingAddress"],
|
227
|
+
"deliverySpecifications": {
|
228
|
+
"specialRestrictions": ["RestrictPOBoxes"],
|
229
|
+
"addressRestrictions": {
|
230
|
+
"type": "Allowed",
|
231
|
+
"restrictions": {
|
232
|
+
"US": {
|
233
|
+
"statesOrRegions": ["WA"],
|
234
|
+
"zipCodes": ["95050", "93405"]
|
235
|
+
},
|
236
|
+
"GB": {
|
237
|
+
"zipCodes": ["72046", "72047"]
|
238
|
+
},
|
239
|
+
"IN": {
|
240
|
+
"statesOrRegions": ["AP"]
|
241
|
+
},
|
242
|
+
"JP": {}
|
243
|
+
}
|
244
|
+
}
|
245
|
+
}
|
246
|
+
}
|
247
|
+
|
248
|
+
response = client.generate_button_signature(button_payload)
|
249
|
+
puts "Button Signature:"
|
250
|
+
puts response
|
251
|
+
```
|
252
|
+
|
253
|
+
### Get Buyer
|
254
|
+
|
255
|
+
```ruby
|
256
|
+
response = client.get_buyer('BUYER_TOKEN', headers: {})
|
257
|
+
if response.code.to_i == 200
|
258
|
+
puts "Get Buyer API Response:"
|
259
|
+
puts response.body
|
260
|
+
else
|
261
|
+
puts "Error: Get Buyer API"
|
262
|
+
puts "Status: #{response.code}"
|
263
|
+
puts response.body
|
264
|
+
end
|
265
|
+
```
|
266
|
+
|
267
|
+
### Create Checkout Session
|
268
|
+
|
269
|
+
```ruby
|
270
|
+
require 'securerandom'
|
271
|
+
|
272
|
+
def createCheckoutSessionPayload = {
|
273
|
+
"webCheckoutDetails": {
|
274
|
+
"checkoutReviewReturnUrl": "https://a.com/merchant-review-page"
|
275
|
+
},
|
276
|
+
"storeId": "amzn1.application-oa2-client.xxxxxxxxxxxxx",
|
277
|
+
"scopes": ["name", "email", "phoneNumber", "billingAddress"],
|
278
|
+
"deliverySpecifications": {
|
279
|
+
"specialRestrictions": ["RestrictPOBoxes"],
|
280
|
+
"addressRestrictions": {
|
281
|
+
"type": "Allowed",
|
282
|
+
"restrictions": {
|
283
|
+
"US": {
|
284
|
+
"statesOrRegions": ["WA"],
|
285
|
+
"zipCodes": ["95050", "93405"]
|
286
|
+
},
|
287
|
+
"GB": {
|
288
|
+
"zipCodes": ["72046", "72047"]
|
289
|
+
},
|
290
|
+
"IN": {
|
291
|
+
"statesOrRegions": ["AP"]
|
292
|
+
},
|
293
|
+
"JP": {}
|
294
|
+
}
|
295
|
+
}
|
296
|
+
}
|
297
|
+
}
|
298
|
+
|
299
|
+
def create_checkout_session_header = {
|
300
|
+
"x-amz-pay-Idempotency-Key": SecureRandom.uuid
|
301
|
+
}
|
302
|
+
|
303
|
+
response = client.create_checkout_session(createCheckoutSessionPayload, headers: create_checkout_session_header)
|
304
|
+
if response.code.to_i == 201 || response.code.to_i == 200
|
305
|
+
puts "Create Checkout Session API Response:"
|
306
|
+
puts response.body
|
307
|
+
else
|
308
|
+
puts "Error: Create Checkout Session API"
|
309
|
+
puts "Status: #{response.code}"
|
310
|
+
puts response.body
|
311
|
+
end
|
312
|
+
```
|
313
|
+
|
314
|
+
### Get Checkout Session
|
315
|
+
|
316
|
+
```ruby
|
317
|
+
response = client.get_checkout_session("checkout_session_id", headers: {})
|
318
|
+
if response.code.to_i == 200
|
319
|
+
puts "Get Checkout Session API Response:"
|
320
|
+
puts response.body
|
321
|
+
else
|
322
|
+
puts "Error: Get Checkout Session API"
|
323
|
+
puts "Status: #{response.code}"
|
324
|
+
puts response.body
|
325
|
+
end
|
326
|
+
```
|
327
|
+
|
328
|
+
### Update Checkout Session
|
329
|
+
|
330
|
+
```ruby
|
331
|
+
def update_checkout_session_payload = {
|
332
|
+
"paymentDetails": {
|
333
|
+
"paymentIntent": "AuthorizeWithCapture",
|
334
|
+
"canHandlePendingAuthorization":false,
|
335
|
+
"softDescriptor": "Descriptor",
|
336
|
+
"chargeAmount": {
|
337
|
+
"amount": "1",
|
338
|
+
"currencyCode": "USD"
|
339
|
+
}
|
340
|
+
},
|
341
|
+
"merchantMetadata": {
|
342
|
+
"merchantReferenceId": "Merchant reference ID",
|
343
|
+
"merchantStoreName": "Merchant store name",
|
344
|
+
"noteToBuyer": "Note to buyer",
|
345
|
+
"customInformation": "Custom information"
|
346
|
+
}
|
347
|
+
}
|
348
|
+
|
349
|
+
response = client.update_checkout_session("checkout_session_id", update_checkout_session_payload, headers: {})
|
350
|
+
if response.code.to_i == 200
|
351
|
+
puts "Update Checkout Session API Response:"
|
352
|
+
puts response.body
|
353
|
+
else
|
354
|
+
puts "Error: Update Checkout Session API"
|
355
|
+
puts "Status: #{response.code}"
|
356
|
+
puts response.body
|
357
|
+
end
|
358
|
+
```
|
359
|
+
|
360
|
+
### Complete Checkout Session
|
361
|
+
|
362
|
+
```ruby
|
363
|
+
def complete_checkout_session_payload = {
|
364
|
+
"chargeAmount": {
|
365
|
+
"amount": "10.00",
|
366
|
+
"currencyCode": "USD"
|
367
|
+
}
|
368
|
+
}
|
369
|
+
|
370
|
+
response = client.complete_checkout_session("checkout_session_id", complete_checkout_session_payload, headers: {})
|
371
|
+
if response.code.to_i == 200
|
372
|
+
puts "Complete Checkout Session API Response:"
|
373
|
+
puts response.body
|
374
|
+
else
|
375
|
+
puts "Error: Complete Checkout Session API"
|
376
|
+
puts "Status: #{response.code}"
|
377
|
+
puts response.body
|
378
|
+
end
|
379
|
+
```
|
380
|
+
|
381
|
+
### Finalize Checkout Session
|
382
|
+
|
383
|
+
```ruby
|
384
|
+
def finalize_checkout_session_payload = {
|
385
|
+
"shippingAddress": {
|
386
|
+
"name": "Susy S",
|
387
|
+
"addressLine1": "11 Ditka Ave",
|
388
|
+
"addressLine2": "Suite 2500",
|
389
|
+
"city": "Chicago",
|
390
|
+
"county": nil,
|
391
|
+
"district": nil,
|
392
|
+
"stateOrRegion": "IL",
|
393
|
+
"postalCode": "60602",
|
394
|
+
"countryCode": "US",
|
395
|
+
"phoneNumber": "800-000-0000"
|
396
|
+
},
|
397
|
+
"billingAddress": {
|
398
|
+
"name": "Susy S",
|
399
|
+
"addressLine1": "11 Ditka Ave",
|
400
|
+
"addressLine2": "Suite 2500",
|
401
|
+
"city": "Chicago",
|
402
|
+
"county": null,
|
403
|
+
"district": null,
|
404
|
+
"stateOrRegion": "IL",
|
405
|
+
"postalCode": "60602",
|
406
|
+
"countryCode": "US",
|
407
|
+
"phoneNumber": "800-000-0000"
|
408
|
+
},
|
409
|
+
"chargeAmount": {
|
410
|
+
"amount": "10",
|
411
|
+
"currencyCode": "USD"
|
412
|
+
},
|
413
|
+
"paymentIntent": "Confirm"
|
414
|
+
}
|
415
|
+
|
416
|
+
response = client.finalize_checkout_session("checkout_session_id", finalize_checkout_session_payload, headers: {})
|
417
|
+
if response.code.to_i == 200 || response.code.to_i == 202
|
418
|
+
puts "Finalize Checkout Session API Response:"
|
419
|
+
puts response.body
|
420
|
+
else
|
421
|
+
puts "Error: Finalize Checkout Session API"
|
422
|
+
puts "Status: #{response.code}"
|
423
|
+
puts response.body
|
424
|
+
end
|
425
|
+
```
|
426
|
+
|
427
|
+
### Get Charge Permission
|
428
|
+
|
429
|
+
```ruby
|
430
|
+
response = client.get_charge_permission("charge_permission_id", headers: {})
|
431
|
+
if response.code.to_i == 200
|
432
|
+
puts "Get Charge Permission API Response:"
|
433
|
+
puts response.body
|
434
|
+
else
|
435
|
+
puts "Error: Get Charge Permission API"
|
436
|
+
puts "Status: #{response.code}"
|
437
|
+
puts response.body
|
438
|
+
end
|
439
|
+
```
|
440
|
+
|
441
|
+
### Update Charge Permission
|
442
|
+
|
443
|
+
```ruby
|
444
|
+
def update_charge_permission_payload = {
|
445
|
+
"merchantMetadata": {
|
446
|
+
"merchantReferenceId": "32-41-323141-32",
|
447
|
+
"merchantStoreName": "ShangameshestStoreFront",
|
448
|
+
"noteToBuyer": "Some Note to buyer",
|
449
|
+
"customInformation": ""
|
450
|
+
}
|
451
|
+
}
|
452
|
+
|
453
|
+
response = client.update_charge_permission("charge_permission_id", update_charge_permission_payload, headers: {})
|
454
|
+
if response.code.to_i == 200
|
455
|
+
puts "Update Charge Permission API Response:"
|
456
|
+
puts response.body
|
457
|
+
else
|
458
|
+
puts "Error: Update Charge Permission API"
|
459
|
+
puts "Status: #{response.code}"
|
460
|
+
puts response.body
|
461
|
+
end
|
462
|
+
```
|
463
|
+
|
464
|
+
### Close Charge Permission
|
465
|
+
|
466
|
+
```ruby
|
467
|
+
def close_charge_permission = {
|
468
|
+
"closureReason": "No more charges required for Store",
|
469
|
+
"cancelPendingCharges": false
|
470
|
+
}
|
471
|
+
|
472
|
+
response = client.close_charge_permission("charge_permission_id", close_charge_permission, headers: {})
|
473
|
+
if response.code.to_i == 200
|
474
|
+
puts "Close Charge Permission API Response:"
|
475
|
+
puts response.body
|
476
|
+
else
|
477
|
+
puts "Error: Close Charge Permission API"
|
478
|
+
puts "Status: #{response.code}"
|
479
|
+
puts response.body
|
480
|
+
end
|
481
|
+
```
|
482
|
+
|
483
|
+
### Create Charge
|
484
|
+
|
485
|
+
```ruby
|
486
|
+
require 'securerandom'
|
487
|
+
|
488
|
+
def create_charge_payload = {
|
489
|
+
"chargePermissionId": "S01-XXXXXX-XXXXXX",
|
490
|
+
"chargeAmount": {
|
491
|
+
"amount": "10.00",
|
492
|
+
"currencyCode": "USD"
|
493
|
+
},
|
494
|
+
"captureNow": true,
|
495
|
+
"softDescriptor": "Descriptor",
|
496
|
+
"canHandlePendingAuthorization": false
|
497
|
+
}
|
498
|
+
|
499
|
+
def create_charge_header = {
|
500
|
+
"x-amz-pay-Idempotency-Key": SecureRandom.uuid
|
501
|
+
}
|
502
|
+
|
503
|
+
response = client.create_charge(create_charge_payload, headers: create_charge_header)
|
504
|
+
if response.code.to_i == 201 || response.code.to_i == 200
|
505
|
+
puts "Create Charge Response:"
|
506
|
+
puts response.body
|
507
|
+
else
|
508
|
+
puts "Error: Create Charge API"
|
509
|
+
puts "Status: #{response.code}"
|
510
|
+
puts response.body
|
511
|
+
end
|
512
|
+
```
|
513
|
+
|
514
|
+
### Get Charge
|
515
|
+
|
516
|
+
```ruby
|
517
|
+
response = client.get_charge('S01-XXXXXX-XXXXXX-XXXXXX', headers: {})
|
518
|
+
if response.code.to_i == 200
|
519
|
+
puts "Get Charge Response:"
|
520
|
+
puts response.body
|
521
|
+
else
|
522
|
+
puts "Error: Get Charge API"
|
523
|
+
puts "Status: #{response.code}"
|
524
|
+
puts response.body
|
525
|
+
end
|
526
|
+
```
|
527
|
+
|
528
|
+
### Capture Charge
|
529
|
+
|
530
|
+
```ruby
|
531
|
+
require 'securerandom'
|
532
|
+
|
533
|
+
def capture_charge_payload = {
|
534
|
+
"captureAmount": {
|
535
|
+
"amount": "1.00",
|
536
|
+
"currencyCode": "USD"
|
537
|
+
},
|
538
|
+
"softDescriptor": "Descriptor"
|
539
|
+
}
|
540
|
+
|
541
|
+
def capture_charge_header = {
|
542
|
+
"x-amz-pay-Idempotency-Key": SecureRandom.uuid
|
543
|
+
}
|
544
|
+
|
545
|
+
response = client.capture_charge('S01-XXXXXX-XXXXXX-XXXXXX', capture_charge_payload, headers: capture_charge_header)
|
546
|
+
if response.code.to_i == 200
|
547
|
+
puts "Capture Charge Response:"
|
548
|
+
puts response.body
|
549
|
+
else
|
550
|
+
puts "Error: Capture Charge API"
|
551
|
+
puts "Status: #{response.code}"
|
552
|
+
puts response.body
|
553
|
+
end
|
554
|
+
```
|
555
|
+
|
556
|
+
### Cancel Charge
|
557
|
+
|
558
|
+
```ruby
|
559
|
+
def cancel_charge_payload = {
|
560
|
+
"cancellationReason": "Charge Cancellation Reason"
|
561
|
+
}
|
562
|
+
|
563
|
+
response = client.cancel_charge('S01-XXXXXX-XXXXXX-XXXXXX', cancel_charge_payload, headers: {})
|
564
|
+
if response.code.to_i == 200
|
565
|
+
puts "Cancel Charge Response:"
|
566
|
+
puts response.body
|
567
|
+
else
|
568
|
+
puts "Error: Cancel Charge API"
|
569
|
+
puts "Status: #{response.code}"
|
570
|
+
puts response.body
|
571
|
+
end
|
572
|
+
```
|
573
|
+
|
574
|
+
### Create Refund
|
575
|
+
|
576
|
+
```ruby
|
577
|
+
def create_refund_payload = {
|
578
|
+
"chargeId": "S01-XXXXXX-XXXXXX-XXXXXX",
|
579
|
+
"refundAmount": {
|
580
|
+
"amount": "1.00",
|
581
|
+
"currencyCode": "USD"
|
582
|
+
},
|
583
|
+
"softDescriptor": "Descriptor"
|
584
|
+
}
|
585
|
+
|
586
|
+
def create_refund_header = {
|
587
|
+
"x-amz-pay-Idempotency-Key": SecureRandom.uuid
|
588
|
+
}
|
589
|
+
|
590
|
+
response = client.create_refund(create_refund_payload, headers: create_refund_header)
|
591
|
+
if response.code.to_i == 201 || response.code.to_i == 200
|
592
|
+
puts "Create Refund Response:"
|
593
|
+
puts response.body
|
594
|
+
else
|
595
|
+
puts "Error: Create Refund API"
|
596
|
+
puts "Status: #{response.code}"
|
597
|
+
puts response.body
|
598
|
+
end
|
599
|
+
```
|
600
|
+
|
601
|
+
### Get Refund
|
602
|
+
|
603
|
+
```ruby
|
604
|
+
response = client.get_refund('S01-XXXXXX-XXXXXX-XXXXXX', headers: {})
|
605
|
+
if response.code.to_i == 200
|
606
|
+
puts "Get Refund Response:"
|
607
|
+
puts response.body
|
608
|
+
else
|
609
|
+
puts "Error: Get Refund API"
|
610
|
+
puts "Status: #{response.code}"
|
611
|
+
puts response.body
|
612
|
+
end
|
218
613
|
```
|
data/lib/amazon_pay/client.rb
CHANGED
@@ -99,4 +99,171 @@ class AmazonPayClient
|
|
99
99
|
def merchant_account_claim(merchant_account_id, payload, headers: {})
|
100
100
|
api_call("#{Constants::MERCHANT_ACCOUNTS_BASE_URL}/#{merchant_account_id}/claim", Constants::POST, payload: payload, headers: headers)
|
101
101
|
end
|
102
|
+
|
103
|
+
# Generates a signature for the given payload
|
104
|
+
# This method is used to generate a signature for an Amazon Pay button payload.
|
105
|
+
# The payload can be provided as either a String or a Hash. If a Hash is provided, it is converted to a JSON string before signing.
|
106
|
+
# @param {Object|String} payload - The payload to be signed, which can be a JSON string or a Hash.
|
107
|
+
# @return {String} The signature for the provided payload.
|
108
|
+
def generate_button_signature(payload)
|
109
|
+
@helper.sign(payload.is_a?(String) ? payload : JSON.generate(payload))
|
110
|
+
end
|
111
|
+
|
112
|
+
# API to retrieve Buyer information
|
113
|
+
# Fetches details of a Buyer using the buyer token provided.
|
114
|
+
# @see https://developer.amazon.com/docs/amazon-pay-api-v2/buyer.html#get-buyer
|
115
|
+
# @param {String} buyer_token - The unique token associated with the Buyer.
|
116
|
+
# @param {Object} headers - Optional headers for the request, such as authorization tokens or custom headers.
|
117
|
+
# @return [HTTPResponse] The response from the API call, which includes the details of the Buyer, such as name, email, and address.
|
118
|
+
def get_buyer(buyer_token, headers: {})
|
119
|
+
api_call("#{Constants::BUYERS_URL}/#{buyer_token}", Constants::GET, headers: headers)
|
120
|
+
end
|
121
|
+
|
122
|
+
# API to create a CheckoutSession object
|
123
|
+
# Creates a new CheckoutSession object.
|
124
|
+
# @see https://developer.amazon.com/docs/amazon-pay-api-v2/checkout-session.html#create-checkout-session
|
125
|
+
# @param {Object} payload - The payload for the request. This should include all the required fields such as chargeAmount, currencyCode, etc.
|
126
|
+
# @param {Object} headers - Optional headers for the request, such as authorization tokens or custom headers.
|
127
|
+
# @return [HTTPResponse] The response from the API call, which includes the details of the newly created CheckoutSession.
|
128
|
+
def create_checkout_session(payload, headers: {})
|
129
|
+
api_call(Constants::CHECKOUT_SESSION_URL, Constants::POST, payload: payload, headers: headers)
|
130
|
+
end
|
131
|
+
|
132
|
+
# API to get a CheckoutSession object
|
133
|
+
# Retrieves details of a previously created CheckoutSession object.
|
134
|
+
# @see https://developer.amazon.com/docs/amazon-pay-api-v2/checkout-session.html#get-checkout-session
|
135
|
+
# @param {String} checkout_session_id - The unique identifier for the CheckoutSession.
|
136
|
+
# @param {Object} headers - Optional headers for the request.
|
137
|
+
# @return [HTTPResponse] The response from the API call, which includes the details of the CheckoutSession object.{Object} [headers=null] - The headers for the request
|
138
|
+
def get_checkout_session(checkout_session_id, headers: {})
|
139
|
+
api_call("#{Constants::CHECKOUT_SESSION_URL}/#{checkout_session_id}", Constants::GET, headers: headers)
|
140
|
+
end
|
141
|
+
|
142
|
+
# API to update a CheckoutSession object
|
143
|
+
# Updates a previously created CheckoutSession object with new information.
|
144
|
+
# @see https://developer.amazon.com/docs/amazon-pay-api-v2/checkout-session.html#update-checkout-session
|
145
|
+
# @param {String} checkout_session_id - The unique identifier for the CheckoutSession.
|
146
|
+
# @param {Object} payload - The payload for the request. This should include the fields that need to be updated.
|
147
|
+
# @param {Object} headers - Optional headers for the request.
|
148
|
+
# @return [HTTPResponse] The response from the API call, which includes the updated details of the CheckoutSession.
|
149
|
+
def update_checkout_session(checkout_session_id, payload, headers: {})
|
150
|
+
api_call("#{Constants::CHECKOUT_SESSION_URL}/#{checkout_session_id}", Constants::PATCH, payload: payload, headers: headers)
|
151
|
+
end
|
152
|
+
|
153
|
+
# API to complete a Checkout Session
|
154
|
+
# Confirms the completion of buyer checkout.
|
155
|
+
# @see https://developer.amazon.com/docs/amazon-pay-api-v2/checkout-session.html#complete-checkout-session
|
156
|
+
# @param {String} checkout_session_id - The unique identifier for the CheckoutSession.
|
157
|
+
# @param {Object} payload - The payload for the request, typically including fields like chargeAmount, currencyCode, etc.
|
158
|
+
# @param {Object} headers - Optional headers for the request.
|
159
|
+
# @return [HTTPResponse] The response from the API call, which confirms the completion of the checkout process.
|
160
|
+
def complete_checkout_session(checkout_session_id, payload, headers: {})
|
161
|
+
api_call("#{Constants::CHECKOUT_SESSION_URL}/#{checkout_session_id}/complete", Constants::POST, payload: payload, headers: headers)
|
162
|
+
end
|
163
|
+
|
164
|
+
# API to finalize a Checkout Session
|
165
|
+
# Finalizes the checkout process by confirming the payment and completing the session.
|
166
|
+
# @see https://developer.amazon.com/docs/amazon-pay-api-v2/checkout-session.html#finalize-checkout-session
|
167
|
+
# @param {String} checkout_session_id - The unique ID of the checkout session that needs to be finalized.
|
168
|
+
# @param {Object} payload - The payload for the request, typically including payment confirmation details.
|
169
|
+
# @param {Object} headers - Optional headers for the request, such as authorization tokens or custom headers.
|
170
|
+
# @return [HTTPResponse] The response from the API call, indicating the success or failure of the checkout finalization.
|
171
|
+
def finalize_checkout_session(checkout_session_id, payload, headers: {})
|
172
|
+
api_call("#{Constants::CHECKOUT_SESSION_URL}/#{checkout_session_id}/finalize", Constants::POST, payload: payload, headers: headers)
|
173
|
+
end
|
174
|
+
|
175
|
+
# API to retrieve a Charge Permission object
|
176
|
+
# Fetches details of a Charge Permission, which is associated with a Checkout Session.
|
177
|
+
# @see https://developer.amazon.com/docs/amazon-pay-api-v2/charge-permission.html#get-charge-permission
|
178
|
+
# @param {String} charge_permission_id - The unique identifier for the Charge Permission.
|
179
|
+
# @param {Object} headers - Optional headers for the request.
|
180
|
+
# @return [HTTPResponse] The response from the API call, including the details of the Charge Permission.
|
181
|
+
def get_charge_permission(charge_permission_id, headers: {})
|
182
|
+
api_call("#{Constants::CHARGE_PERMISSIONS_URL}/#{charge_permission_id}", Constants::GET, headers: headers)
|
183
|
+
end
|
184
|
+
|
185
|
+
# API to update a Charge Permission object
|
186
|
+
# Updates a previously created Charge Permission with new information.
|
187
|
+
# @see https://developer.amazon.com/docs/amazon-pay-api-v2/charge-permission.html#update-charge-permission
|
188
|
+
# @param {String} charge_permission_id - The unique identifier for the Charge Permission.
|
189
|
+
# @param {Object} payload - The payload for the request. This should include the fields that need to be updated.
|
190
|
+
# @param {Object} headers - Optional headers for the request.
|
191
|
+
# @return [HTTPResponse] The response from the API call, including the updated details of the Charge Permission.
|
192
|
+
def update_charge_permission(charge_permission_id, payload, headers: {})
|
193
|
+
api_call("#{Constants::CHARGE_PERMISSIONS_URL}/#{charge_permission_id}", Constants::PATCH, payload: payload, headers: headers)
|
194
|
+
end
|
195
|
+
|
196
|
+
# API to close a Charge Permission object
|
197
|
+
# Closes a Charge Permission, preventing further charges.
|
198
|
+
# @see https://developer.amazon.com/docs/amazon-pay-api-v2/charge-permission.html#close-charge-permission
|
199
|
+
# @param {String} charge_permission_id - The unique identifier for the Charge Permission.
|
200
|
+
# @param {Object} payload - The payload for the request, typically including a reason for closure.
|
201
|
+
# @param {Object} headers - Optional headers for the request.
|
202
|
+
# @return [HTTPResponse] The response from the API call, confirming the closure of the Charge Permission.
|
203
|
+
def close_charge_permission(charge_permission_id, payload, headers: {})
|
204
|
+
api_call("#{Constants::CHARGE_PERMISSIONS_URL}/#{charge_permission_id}/close", Constants::DELETE, payload: payload, headers: headers)
|
205
|
+
end
|
206
|
+
|
207
|
+
# API to create a new charge
|
208
|
+
# Initiates a new charge with the provided payment details.
|
209
|
+
# @see https://developer.amazon.com/docs/amazon-pay-api-v2/charge.html#create-charge
|
210
|
+
# @param {Object} payload - The payload containing payment details, such as the amount and currency.
|
211
|
+
# @param {Object} headers - Optional headers for the request, such as authorization tokens or custom headers.
|
212
|
+
# @return [HTTPResponse] The response from the API call, which includes details of the created charge.
|
213
|
+
def create_charge(payload, headers: {})
|
214
|
+
api_call(Constants::CHARGES_URL, Constants::POST, payload: payload, headers: headers)
|
215
|
+
end
|
216
|
+
|
217
|
+
# API to retrieve charge details
|
218
|
+
# Retrieves details of an existing charge using its unique charge ID.
|
219
|
+
# @see https://developer.amazon.com/docs/amazon-pay-api-v2/charge.html#get-charge
|
220
|
+
# @param {String} charge_id - The unique ID of the charge to retrieve.
|
221
|
+
# @param {Object} headers - Optional headers for the request, such as authorization tokens or custom headers.
|
222
|
+
# @return [HTTPResponse] The response from the API call, which includes details of the requested charge.
|
223
|
+
def get_charge(charge_id, headers: {})
|
224
|
+
api_call("#{Constants::CHARGES_URL}/#{charge_id}", Constants::GET, headers: headers)
|
225
|
+
end
|
226
|
+
|
227
|
+
# API to capture a charge
|
228
|
+
# Captures an authorized charge to collect the funds.
|
229
|
+
# @see https://developer.amazon.com/docs/amazon-pay-api-v2/charge.html#capture-charge
|
230
|
+
# @param {String} charge_id - The unique ID of the charge to capture.
|
231
|
+
# @param {Object} payload - The payload containing capture details, such as the amount to capture.
|
232
|
+
# @param {Object} headers - Optional headers for the request, such as authorization tokens or custom headers.
|
233
|
+
# @return [HTTPResponse] The response from the API call, which includes details of the captured charge.
|
234
|
+
def capture_charge(charge_id, payload, headers: {})
|
235
|
+
api_call("#{Constants::CHARGES_URL}/#{charge_id}/capture", Constants::POST, payload: payload, headers: headers)
|
236
|
+
end
|
237
|
+
|
238
|
+
# API to cancel a charge
|
239
|
+
# Cancels an existing charge, preventing it from being captured.
|
240
|
+
# @see https://developer.amazon.com/docs/amazon-pay-api-v2/charge.html#cancel-charge
|
241
|
+
# @param {String} charge_id - The unique ID of the charge to cancel.
|
242
|
+
# @param {Object} payload - The payload containing cancellation details.
|
243
|
+
# @param {Object} headers - Optional headers for the request, such as authorization tokens or custom headers.
|
244
|
+
# @return [HTTPResponse] The response from the API call, which confirms the cancellation of the charge.
|
245
|
+
def cancel_charge(charge_id, payload, headers: {})
|
246
|
+
api_call("#{Constants::CHARGES_URL}/#{charge_id}/cancel", Constants::DELETE, payload: payload, headers: headers)
|
247
|
+
end
|
248
|
+
|
249
|
+
# API to create a refund
|
250
|
+
# Initiates a new refund for a previously captured charge.
|
251
|
+
# @see https://developer.amazon.com/docs/amazon-pay-api-v2/refund.html#create-refund
|
252
|
+
# @param {Object} payload - The payload containing refund details, such as the amount and currency.
|
253
|
+
# @param {Object} headers - Optional headers for the request, such as authorization tokens or custom headers.
|
254
|
+
# @return [HTTPResponse] The response from the API call, which includes details of the created refund.
|
255
|
+
def create_refund(payload, headers: {})
|
256
|
+
api_call(Constants::REFUNDS_URL, Constants::POST, payload: payload, headers: headers)
|
257
|
+
end
|
258
|
+
|
259
|
+
# API to retrieve refund details
|
260
|
+
# Retrieves details of an existing refund using its unique refund ID.
|
261
|
+
# @see https://developer.amazon.com/docs/amazon-pay-api-v2/refund.html#get-refund
|
262
|
+
# @param {String} refund_id - The unique ID of the refund to retrieve.
|
263
|
+
# @param {Object} headers - Optional headers for the request, such as authorization tokens or custom headers.
|
264
|
+
# @return [HTTPResponse] The response from the API call, which includes details of the requested refund.
|
265
|
+
def get_refund(refund_id, headers: {})
|
266
|
+
api_call("#{Constants::REFUNDS_URL}/#{refund_id}", Constants::GET, headers: headers)
|
267
|
+
end
|
268
|
+
|
102
269
|
end
|
data/lib/amazon_pay/constants.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'net/http'
|
2
2
|
|
3
3
|
module Constants
|
4
|
-
SDK_TYPE = "
|
5
|
-
SDK_VERSION = "1.
|
4
|
+
SDK_TYPE = "amazon-pay-api-sdk-ruby".freeze
|
5
|
+
SDK_VERSION = "1.1.0".freeze
|
6
6
|
API_VERSION = "v2".freeze
|
7
7
|
API_ENDPOINTS = {
|
8
8
|
'na' => 'pay-api.amazon.com',
|
@@ -32,11 +32,18 @@ module Constants
|
|
32
32
|
LIVE = 'LIVE-'
|
33
33
|
SANDBOX = 'SANDBOX-'
|
34
34
|
MERCHANT_ACCOUNTS_BASE_URL = 'merchantAccounts'.freeze
|
35
|
+
GET = 'GET'.freeze
|
35
36
|
POST = 'POST'.freeze
|
36
37
|
PATCH = 'PATCH'.freeze
|
38
|
+
DELETE = 'DELETE'.freeze
|
37
39
|
MAX_RETRIES = 3.freeze
|
38
40
|
BACKOFF_TIMES = [1, 2, 4].freeze # Define backoff times for retries
|
39
41
|
RETRYABLE_ERROR_CODES = [408, 429, 500, 502, 503, 504].freeze
|
40
42
|
HTTP_OK = '200'
|
41
43
|
HTTP_SERVER_ERROR = '500'
|
44
|
+
BUYERS_URL = 'buyers'.freeze
|
45
|
+
CHECKOUT_SESSION_URL = 'checkoutSessions'.freeze
|
46
|
+
CHARGE_PERMISSIONS_URL = 'chargePermissions'.freeze
|
47
|
+
CHARGES_URL = 'charges'.freeze
|
48
|
+
REFUNDS_URL = 'refunds'.freeze
|
42
49
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: amazon-pay-api-sdk-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- AmazonPay
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-08-
|
11
|
+
date: 2024-08-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: base64
|
@@ -70,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
70
70
|
- !ruby/object:Gem::Version
|
71
71
|
version: '0'
|
72
72
|
requirements: []
|
73
|
-
rubygems_version: 3.4
|
73
|
+
rubygems_version: 3.5.4
|
74
74
|
signing_key:
|
75
75
|
specification_version: 4
|
76
76
|
summary: This is an AmazonPay Ruby SDK
|