amazon-pay-api-sdk-ruby 1.0.0 → 1.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: be95e6a94ffd92f2b63c434fae57106167e710b78e37ec2ee769055400498153
4
- data.tar.gz: b37aec741850a99fb89cc241f396da9fe49e0de47f910232101ba32c8c8bafb0
3
+ metadata.gz: 428da5a80e49d6cf400205eea58757174f259abce2bb6cc7a83aecd0c1554f5f
4
+ data.tar.gz: b809960b865a226d7796e506d1712759c0db90119cd886942b5aa9d6ed125681
5
5
  SHA512:
6
- metadata.gz: 82928d3a73a42da02eb620166c86056402773fd700ff6d0e717d0610ff25ef02f1c84ef9bf4cd4288b70df489d0333b30297cee3b40bfbcdb34e3a3a057816b9
7
- data.tar.gz: 575aa9e43e074704128e085ac94d2dc3063d2dc4add84eebb5ea9d860c051fea17c1fe139b2339ceca0f2028a2ecd1e0cc8fb7fd48bf47d547a12d1f8a8b457e
6
+ metadata.gz: 70c5fb962cf91183aca482ad024752e41a11e398cc666bc87aae026cfbef0efa813b0e36d3b5352f184638efe633f6811927db2a29607b115e59fb1af05836a4
7
+ data.tar.gz: 4f62e310db2e153b5c3110a36498e66a81f0f99d9bed70de7c8722feb1c076392b510233df447f37663e23634a5d567b118806beadc01749947de3817efda2df
data/README.md CHANGED
@@ -86,35 +86,17 @@ createMerchantAccountPayload = {
86
86
  }
87
87
  }
88
88
  },
89
- "beneficiaryOwners": [
90
- {
91
- "personId": "BO1",
92
- "personFullName": "ABC ABC",
89
+ "beneficiaryOwners": [{
90
+ "personFullName": "Rufus Rufus",
93
91
  "residentialAddress": {
94
- "addressLine1": "122, ABC XYZ",
95
- "addressLine2": "XYZ",
96
- "city": "XYZ",
97
- "stateOrRegion": "XYZ",
98
- "postalCode": "123456",
92
+ "addressLine1": "4-7, Sunny Mansion 203",
93
+ "addressLine2": "Boren Ave",
94
+ "city": "Chiryushi",
95
+ "stateOrRegion": "AICHI",
96
+ "postalCode": "4720021",
99
97
  "countryCode": "JP",
100
98
  "phoneNumber": {
101
- "countryCode": "123",
102
- "number": "2062062061"
103
- }
104
- }
105
- },
106
- {
107
- "personId": "BO2",
108
- "personFullName": "ABC ABC",
109
- "residentialAddress": {
110
- "addressLine1": "122, ABC XYZ",
111
- "addressLine2": "XYZ",
112
- "city": "XYZ",
113
- "stateOrRegion": "XYZ",
114
- "postalCode": "123456",
115
- "countryCode": "JP",
116
- "phoneNumber": {
117
- "countryCode": "123",
99
+ "countryCode": "81",
118
100
  "number": "2062062061"
119
101
  }
120
102
  }
@@ -135,7 +117,7 @@ createMerchantAccountPayload = {
135
117
  "storeName": "ABC ABC",
136
118
  "privacyPolicyUrl": "http://www.abc.com/privacy",
137
119
  "storeStatus": {
138
- "state": "Active",
120
+ "state": "ACTIVE",
139
121
  "reasonCode": nil
140
122
  }
141
123
  },
@@ -146,11 +128,7 @@ createMerchantAccountPayload = {
146
128
  }
147
129
  }
148
130
 
149
- createMerchantAccountHeader = {
150
- "x-amz-pay-Idempotency-Key": "idempotency-key"
151
- }
152
-
153
- response = client.create_merchant_account(createMerchantAccountPayload, headers: createMerchantAccountHeader)
131
+ response = client.create_merchant_account(createMerchantAccountPayload, headers: {})
154
132
  if response.code.to_i == 201 || response.code.to_i == 200
155
133
  puts "Create Merchant Account API Response:"
156
134
  puts response.body
@@ -183,7 +161,9 @@ updateMerchantAccountPayload = {
183
161
  }
184
162
  }
185
163
 
186
- updateMerchantAccountHeader = {}
164
+ updateMerchantAccountHeader = {
165
+ "x-amz-pay-authToken" : "AUTH_TOKEN"
166
+ }
187
167
 
188
168
  response = client.update_merchant_account('XXXXXXXXX', updateMerchantAccountPayload, headers: updateMerchantAccountHeader)
189
169
  if response.code.to_i == 200
@@ -207,12 +187,561 @@ merchantAccountClaimPayload = {
207
187
  }
208
188
 
209
189
  response = client.merchant_account_claim('XXXXXXXXX', merchantAccountClaimPayload, headers: {})
210
- if response.code.to_i == 303
190
+ if response.code.to_i == 303 || response.code.to_i == 200
211
191
  puts "Merchant Account Claim API Response:"
212
192
  puts response.body
193
+ puts "Headers:"
194
+ puts response.to_hash.to_json
213
195
  else
214
196
  puts "Error: Merchant Account Claim API"
215
197
  puts "Status: #{response.code}"
216
198
  puts response.body
217
199
  end
200
+ ```
201
+
202
+ ### Generate Button Signature
203
+
204
+ ```ruby
205
+ def button_payload = {
206
+ "webCheckoutDetails": {
207
+ "checkoutReviewReturnUrl": "https://a.com/merchant-review-page"
208
+ },
209
+ "storeId": "amzn1.application-oa2-client.xxxxxxxxxxxx",
210
+ "scopes": ["name", "email", "phoneNumber", "billingAddress"],
211
+ "deliverySpecifications": {
212
+ "specialRestrictions": ["RestrictPOBoxes"],
213
+ "addressRestrictions": {
214
+ "type": "Allowed",
215
+ "restrictions": {
216
+ "US": {
217
+ "statesOrRegions": ["WA"],
218
+ "zipCodes": ["95050", "93405"]
219
+ },
220
+ "GB": {
221
+ "zipCodes": ["72046", "72047"]
222
+ },
223
+ "IN": {
224
+ "statesOrRegions": ["AP"]
225
+ },
226
+ "JP": {}
227
+ }
228
+ }
229
+ }
230
+ }
231
+
232
+ response = client.generate_button_signature(button_payload)
233
+ puts "Button Signature:"
234
+ puts response
235
+ ```
236
+
237
+ ### Get Buyer
238
+
239
+ ```ruby
240
+ response = client.get_buyer('BUYER_TOKEN', headers: {})
241
+ if response.code.to_i == 200
242
+ puts "Get Buyer API Response:"
243
+ puts response.body
244
+ else
245
+ puts "Error: Get Buyer API"
246
+ puts "Status: #{response.code}"
247
+ puts response.body
248
+ end
249
+ ```
250
+
251
+ ### Create Checkout Session
252
+
253
+ ```ruby
254
+ require 'securerandom'
255
+
256
+ def createCheckoutSessionPayload = {
257
+ "webCheckoutDetails": {
258
+ "checkoutReviewReturnUrl": "https://a.com/merchant-review-page"
259
+ },
260
+ "storeId": "amzn1.application-oa2-client.xxxxxxxxxxxxx",
261
+ "scopes": ["name", "email", "phoneNumber", "billingAddress"],
262
+ "deliverySpecifications": {
263
+ "specialRestrictions": ["RestrictPOBoxes"],
264
+ "addressRestrictions": {
265
+ "type": "Allowed",
266
+ "restrictions": {
267
+ "US": {
268
+ "statesOrRegions": ["WA"],
269
+ "zipCodes": ["95050", "93405"]
270
+ },
271
+ "GB": {
272
+ "zipCodes": ["72046", "72047"]
273
+ },
274
+ "IN": {
275
+ "statesOrRegions": ["AP"]
276
+ },
277
+ "JP": {}
278
+ }
279
+ }
280
+ }
281
+ }
282
+
283
+ def create_checkout_session_header = {
284
+ "x-amz-pay-Idempotency-Key": SecureRandom.uuid
285
+ }
286
+
287
+ response = client.create_checkout_session(createCheckoutSessionPayload, headers: create_checkout_session_header)
288
+ if response.code.to_i == 201 || response.code.to_i == 200
289
+ puts "Create Checkout Session API Response:"
290
+ puts response.body
291
+ else
292
+ puts "Error: Create Checkout Session API"
293
+ puts "Status: #{response.code}"
294
+ puts response.body
295
+ end
296
+ ```
297
+
298
+ ### Get Checkout Session
299
+
300
+ ```ruby
301
+ response = client.get_checkout_session("checkout_session_id", headers: {})
302
+ if response.code.to_i == 200
303
+ puts "Get Checkout Session API Response:"
304
+ puts response.body
305
+ else
306
+ puts "Error: Get Checkout Session API"
307
+ puts "Status: #{response.code}"
308
+ puts response.body
309
+ end
310
+ ```
311
+
312
+ ### Update Checkout Session
313
+
314
+ ```ruby
315
+ def update_checkout_session_payload = {
316
+ "paymentDetails": {
317
+ "paymentIntent": "AuthorizeWithCapture",
318
+ "canHandlePendingAuthorization":false,
319
+ "softDescriptor": "Descriptor",
320
+ "chargeAmount": {
321
+ "amount": "1",
322
+ "currencyCode": "USD"
323
+ }
324
+ },
325
+ "merchantMetadata": {
326
+ "merchantReferenceId": "Merchant reference ID",
327
+ "merchantStoreName": "Merchant store name",
328
+ "noteToBuyer": "Note to buyer",
329
+ "customInformation": "Custom information"
330
+ }
331
+ }
332
+
333
+ response = client.update_checkout_session("checkout_session_id", update_checkout_session_payload, headers: {})
334
+ if response.code.to_i == 200
335
+ puts "Update Checkout Session API Response:"
336
+ puts response.body
337
+ else
338
+ puts "Error: Update Checkout Session API"
339
+ puts "Status: #{response.code}"
340
+ puts response.body
341
+ end
342
+ ```
343
+
344
+ ### Complete Checkout Session
345
+
346
+ ```ruby
347
+ def complete_checkout_session_payload = {
348
+ "chargeAmount": {
349
+ "amount": "10.00",
350
+ "currencyCode": "USD"
351
+ }
352
+ }
353
+
354
+ response = client.complete_checkout_session("checkout_session_id", complete_checkout_session_payload, headers: {})
355
+ if response.code.to_i == 200
356
+ puts "Complete Checkout Session API Response:"
357
+ puts response.body
358
+ else
359
+ puts "Error: Complete Checkout Session API"
360
+ puts "Status: #{response.code}"
361
+ puts response.body
362
+ end
363
+ ```
364
+
365
+ ### Finalize Checkout Session
366
+
367
+ ```ruby
368
+ def finalize_checkout_session_payload = {
369
+ "shippingAddress": {
370
+ "name": "Susy S",
371
+ "addressLine1": "11 Ditka Ave",
372
+ "addressLine2": "Suite 2500",
373
+ "city": "Chicago",
374
+ "county": nil,
375
+ "district": nil,
376
+ "stateOrRegion": "IL",
377
+ "postalCode": "60602",
378
+ "countryCode": "US",
379
+ "phoneNumber": "800-000-0000"
380
+ },
381
+ "billingAddress": {
382
+ "name": "Susy S",
383
+ "addressLine1": "11 Ditka Ave",
384
+ "addressLine2": "Suite 2500",
385
+ "city": "Chicago",
386
+ "county": null,
387
+ "district": null,
388
+ "stateOrRegion": "IL",
389
+ "postalCode": "60602",
390
+ "countryCode": "US",
391
+ "phoneNumber": "800-000-0000"
392
+ },
393
+ "chargeAmount": {
394
+ "amount": "10",
395
+ "currencyCode": "USD"
396
+ },
397
+ "paymentIntent": "Confirm"
398
+ }
399
+
400
+ response = client.finalize_checkout_session("checkout_session_id", finalize_checkout_session_payload, headers: {})
401
+ if response.code.to_i == 200 || response.code.to_i == 202
402
+ puts "Finalize Checkout Session API Response:"
403
+ puts response.body
404
+ else
405
+ puts "Error: Finalize Checkout Session API"
406
+ puts "Status: #{response.code}"
407
+ puts response.body
408
+ end
409
+ ```
410
+
411
+ ### Get Charge Permission
412
+
413
+ ```ruby
414
+ response = client.get_charge_permission("charge_permission_id", headers: {})
415
+ if response.code.to_i == 200
416
+ puts "Get Charge Permission API Response:"
417
+ puts response.body
418
+ else
419
+ puts "Error: Get Charge Permission API"
420
+ puts "Status: #{response.code}"
421
+ puts response.body
422
+ end
423
+ ```
424
+
425
+ ### Update Charge Permission
426
+
427
+ ```ruby
428
+ def update_charge_permission_payload = {
429
+ "merchantMetadata": {
430
+ "merchantReferenceId": "32-41-323141-32",
431
+ "merchantStoreName": "ShangameshestStoreFront",
432
+ "noteToBuyer": "Some Note to buyer",
433
+ "customInformation": ""
434
+ }
435
+ }
436
+
437
+ response = client.update_charge_permission("charge_permission_id", update_charge_permission_payload, headers: {})
438
+ if response.code.to_i == 200
439
+ puts "Update Charge Permission API Response:"
440
+ puts response.body
441
+ else
442
+ puts "Error: Update Charge Permission API"
443
+ puts "Status: #{response.code}"
444
+ puts response.body
445
+ end
446
+ ```
447
+
448
+ ### Close Charge Permission
449
+
450
+ ```ruby
451
+ def close_charge_permission = {
452
+ "closureReason": "No more charges required for Store",
453
+ "cancelPendingCharges": false
454
+ }
455
+
456
+ response = client.close_charge_permission("charge_permission_id", close_charge_permission, headers: {})
457
+ if response.code.to_i == 200
458
+ puts "Close Charge Permission API Response:"
459
+ puts response.body
460
+ else
461
+ puts "Error: Close Charge Permission API"
462
+ puts "Status: #{response.code}"
463
+ puts response.body
464
+ end
465
+ ```
466
+
467
+ ### Create Charge
468
+
469
+ ```ruby
470
+ require 'securerandom'
471
+
472
+ def create_charge_payload = {
473
+ "chargePermissionId": "S01-XXXXXX-XXXXXX",
474
+ "chargeAmount": {
475
+ "amount": "10.00",
476
+ "currencyCode": "USD"
477
+ },
478
+ "captureNow": true,
479
+ "softDescriptor": "Descriptor",
480
+ "canHandlePendingAuthorization": false
481
+ }
482
+
483
+ def create_charge_header = {
484
+ "x-amz-pay-Idempotency-Key": SecureRandom.uuid
485
+ }
486
+
487
+ response = client.create_charge(create_charge_payload, headers: create_charge_header)
488
+ if response.code.to_i == 201 || response.code.to_i == 200
489
+ puts "Create Charge Response:"
490
+ puts response.body
491
+ else
492
+ puts "Error: Create Charge API"
493
+ puts "Status: #{response.code}"
494
+ puts response.body
495
+ end
496
+ ```
497
+
498
+ ### Get Charge
499
+
500
+ ```ruby
501
+ response = client.get_charge('S01-XXXXXX-XXXXXX-XXXXXX', headers: {})
502
+ if response.code.to_i == 200
503
+ puts "Get Charge Response:"
504
+ puts response.body
505
+ else
506
+ puts "Error: Get Charge API"
507
+ puts "Status: #{response.code}"
508
+ puts response.body
509
+ end
510
+ ```
511
+
512
+ ### Capture Charge
513
+
514
+ ```ruby
515
+ require 'securerandom'
516
+
517
+ def capture_charge_payload = {
518
+ "captureAmount": {
519
+ "amount": "1.00",
520
+ "currencyCode": "USD"
521
+ },
522
+ "softDescriptor": "Descriptor"
523
+ }
524
+
525
+ def capture_charge_header = {
526
+ "x-amz-pay-Idempotency-Key": SecureRandom.uuid
527
+ }
528
+
529
+ response = client.capture_charge('S01-XXXXXX-XXXXXX-XXXXXX', capture_charge_payload, headers: capture_charge_header)
530
+ if response.code.to_i == 200
531
+ puts "Capture Charge Response:"
532
+ puts response.body
533
+ else
534
+ puts "Error: Capture Charge API"
535
+ puts "Status: #{response.code}"
536
+ puts response.body
537
+ end
538
+ ```
539
+
540
+ ### Cancel Charge
541
+
542
+ ```ruby
543
+ def cancel_charge_payload = {
544
+ "cancellationReason": "Charge Cancellation Reason"
545
+ }
546
+
547
+ response = client.cancel_charge('S01-XXXXXX-XXXXXX-XXXXXX', cancel_charge_payload, headers: {})
548
+ if response.code.to_i == 200
549
+ puts "Cancel Charge Response:"
550
+ puts response.body
551
+ else
552
+ puts "Error: Cancel Charge API"
553
+ puts "Status: #{response.code}"
554
+ puts response.body
555
+ end
556
+ ```
557
+
558
+ ### Create Refund
559
+
560
+ ```ruby
561
+ def create_refund_payload = {
562
+ "chargeId": "S01-XXXXXX-XXXXXX-XXXXXX",
563
+ "refundAmount": {
564
+ "amount": "1.00",
565
+ "currencyCode": "USD"
566
+ },
567
+ "softDescriptor": "Descriptor"
568
+ }
569
+
570
+ def create_refund_header = {
571
+ "x-amz-pay-Idempotency-Key": SecureRandom.uuid
572
+ }
573
+
574
+ response = client.create_refund(create_refund_payload, headers: create_refund_header)
575
+ if response.code.to_i == 201 || response.code.to_i == 200
576
+ puts "Create Refund Response:"
577
+ puts response.body
578
+ else
579
+ puts "Error: Create Refund API"
580
+ puts "Status: #{response.code}"
581
+ puts response.body
582
+ end
583
+ ```
584
+
585
+ ### Get Refund
586
+
587
+ ```ruby
588
+ response = client.get_refund('S01-XXXXXX-XXXXXX-XXXXXX', headers: {})
589
+ if response.code.to_i == 200
590
+ puts "Get Refund Response:"
591
+ puts response.body
592
+ else
593
+ puts "Error: Get Refund API"
594
+ puts "Status: #{response.code}"
595
+ puts response.body
596
+ end
597
+ ```
598
+
599
+ ### Get Reports
600
+
601
+ ```ruby
602
+ response = client.get_reports(query_params: {})
603
+ if response.code.to_i == 200
604
+ puts "Get Reports Response:"
605
+ puts response.body
606
+ else
607
+ puts "Error: Get Reports API"
608
+ puts "Status: #{response.code}"
609
+ puts response.body
610
+ end
611
+ ```
612
+
613
+ ### Get Report By Id
614
+
615
+ ```ruby
616
+ def report_id = "123456789"
617
+ response = client.get_report_by_id(report_id, headers: {})
618
+ if response.code.to_i == 200
619
+ puts "Get Report By Id Response:"
620
+ puts response.body
621
+ else
622
+ puts "Error: Get Report By Id API"
623
+ puts "Status: #{response.code}"
624
+ puts response.body
625
+ end
626
+ ```
627
+
628
+ ### Create Report
629
+
630
+ ```ruby
631
+ def create_report_payload = {
632
+ "reportType": "_GET_FLAT_FILE_OFFAMAZONPAYMENTS_SANDBOX_SETTLEMENT_DATA_",
633
+ "startTime": "20240810T000000Z",
634
+ "endTime": "20240815T000000Z"
635
+ }
636
+ response = client.create_report(create_report_payload, headers: {"x-amz-pay-Idempotency-Key": SecureRandom.uuid})
637
+ if response.code.to_i == 201
638
+ puts "Create Report Response:"
639
+ puts response.body
640
+ else
641
+ puts "Error: Create Report API"
642
+ puts "Status: #{response.code}"
643
+ puts response.body
644
+ end
645
+ ```
646
+
647
+ ### Get Report Document
648
+
649
+
650
+ ```ruby
651
+ def report_document_id = "123456789"
652
+ response = client.get_report_document(report_document_id, headers: {})
653
+ if response.code.to_i == 200
654
+ puts "Get Report Document Response:"
655
+ puts response.body
656
+ else
657
+ puts "Error: Get Report Document API"
658
+ puts "Status: #{response.code}"
659
+ puts response.body
660
+ end
661
+ ```
662
+
663
+ ### Get Report Schedules
664
+
665
+ ```ruby
666
+ def query_params = {
667
+ "reportType": "_GET_FLAT_FILE_OFFAMAZONPAYMENTS_SANDBOX_SETTLEMENT_DATA_",
668
+ }
669
+ response = client.get_report_schedules(query_params: query_params, headers: {})
670
+ if response.code.to_i == 200
671
+ puts "Get Report Schedules Response:"
672
+ puts response.body
673
+ else
674
+ puts "Error: Get Report Schedules API"
675
+ puts "Status: #{response.code}"
676
+ puts response.body
677
+ end
678
+ ```
679
+
680
+ ### Get Report Schedule By ID
681
+
682
+ ```ruby
683
+ def report_schedule_id = "123456789"
684
+ response = client.get_report_schedule_by_id(report_schedule_id, headers: {})
685
+ if response.code.to_i == 200
686
+ puts "Get Report Schedule By ID Response:"
687
+ puts response.body
688
+ else
689
+ puts "Error: Get Report Schedule By ID API"
690
+ puts "Status: #{response.code}"
691
+ puts response.body
692
+ end
693
+ ```
694
+
695
+ ### Create Report Schedule
696
+
697
+ ```ruby
698
+ def create_report_schdule_payload = {
699
+ "reportType": "_GET_FLAT_FILE_OFFAMAZONPAYMENTS_SANDBOX_SETTLEMENT_DATA_",
700
+ "scheduleFrequency": "P1D",
701
+ "nextReportCreationTime": "20241001T000000Z"
702
+ }
703
+ response = client.create_report_schedule(create_report_schdule_payload, headers: {"x-amz-pay-Idempotency-Key": SecureRandom.uuid}, query_params: {})
704
+ if response.code.to_i == 201
705
+ puts "Create Report Schedule Response:"
706
+ puts response.body
707
+ else
708
+ puts "Error: Create Report Schedule API"
709
+ puts "Status: #{response.code}"
710
+ puts response.body
711
+ end
712
+ ```
713
+
714
+ #### Cancel Report Schedule
715
+
716
+ ```ruby
717
+ def report_schedule_id = "123456789"
718
+ response = client.cancel_report_schedule(report_schedule_id, headers: {})
719
+ if response.code.to_i == 200
720
+ puts "Cancel Report Schedule Schedule Response:"
721
+ puts response.body
722
+ else
723
+ puts "Error: Cancel Report Schedule Schedule API"
724
+ puts "Status: #{response.code}"
725
+ puts response.body
726
+ end
727
+ ```
728
+
729
+ ### Get Disbursements
730
+
731
+ ```ruby
732
+ def query_params = {
733
+ "startTime": '20240810T000000Z',
734
+ "endTime": '20240815T000000Z'
735
+ "pageSize": "30",
736
+ "nextToken": ""
737
+ }
738
+ response = client.get_disbursements(query_params: {}, headers: {})
739
+ if response.code.to_i == 200
740
+ puts "Get Disbursements Response:"
741
+ puts response.body
742
+ else
743
+ puts "Error: Get Disbursements API"
744
+ puts "Status: #{response.code}"
745
+ puts response.body
746
+ end
218
747
  ```
@@ -47,7 +47,6 @@ class AmazonPayClient
47
47
 
48
48
  # Increment the retry counter
49
49
  retries += 1
50
- print "Retrying\n"
51
50
  # Raise an exception to force a retry
52
51
  raise "Transient error: #{response.code}" # Force retry
53
52
  end
@@ -99,4 +98,260 @@ class AmazonPayClient
99
98
  def merchant_account_claim(merchant_account_id, payload, headers: {})
100
99
  api_call("#{Constants::MERCHANT_ACCOUNTS_BASE_URL}/#{merchant_account_id}/claim", Constants::POST, payload: payload, headers: headers)
101
100
  end
101
+
102
+ # Generates a signature for the given payload
103
+ # This method is used to generate a signature for an Amazon Pay button payload.
104
+ # 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.
105
+ # @param {Object|String} payload - The payload to be signed, which can be a JSON string or a Hash.
106
+ # @return {String} The signature for the provided payload.
107
+ def generate_button_signature(payload)
108
+ @helper.sign(payload.is_a?(String) ? payload : JSON.generate(payload))
109
+ end
110
+
111
+ # API to retrieve Buyer information
112
+ # Fetches details of a Buyer using the buyer token provided.
113
+ # @see https://developer.amazon.com/docs/amazon-pay-api-v2/buyer.html#get-buyer
114
+ # @param {String} buyer_token - The unique token associated with the Buyer.
115
+ # @param {Object} headers - Optional headers for the request, such as authorization tokens or custom headers.
116
+ # @return [HTTPResponse] The response from the API call, which includes the details of the Buyer, such as name, email, and address.
117
+ def get_buyer(buyer_token, headers: {})
118
+ api_call("#{Constants::BUYERS_URL}/#{buyer_token}", Constants::GET, headers: headers)
119
+ end
120
+
121
+ # API to create a CheckoutSession object
122
+ # Creates a new CheckoutSession object.
123
+ # @see https://developer.amazon.com/docs/amazon-pay-api-v2/checkout-session.html#create-checkout-session
124
+ # @param {Object} payload - The payload for the request. This should include all the required fields such as chargeAmount, currencyCode, etc.
125
+ # @param {Object} headers - Optional headers for the request, such as authorization tokens or custom headers.
126
+ # @return [HTTPResponse] The response from the API call, which includes the details of the newly created CheckoutSession.
127
+ def create_checkout_session(payload, headers: {})
128
+ api_call(Constants::CHECKOUT_SESSION_URL, Constants::POST, payload: payload, headers: headers)
129
+ end
130
+
131
+ # API to get a CheckoutSession object
132
+ # Retrieves details of a previously created CheckoutSession object.
133
+ # @see https://developer.amazon.com/docs/amazon-pay-api-v2/checkout-session.html#get-checkout-session
134
+ # @param {String} checkout_session_id - The unique identifier for the CheckoutSession.
135
+ # @param {Object} headers - Optional headers for the request.
136
+ # @return [HTTPResponse] The response from the API call, which includes the details of the CheckoutSession object.{Object} [headers=null] - The headers for the request
137
+ def get_checkout_session(checkout_session_id, headers: {})
138
+ api_call("#{Constants::CHECKOUT_SESSION_URL}/#{checkout_session_id}", Constants::GET, headers: headers)
139
+ end
140
+
141
+ # API to update a CheckoutSession object
142
+ # Updates a previously created CheckoutSession object with new information.
143
+ # @see https://developer.amazon.com/docs/amazon-pay-api-v2/checkout-session.html#update-checkout-session
144
+ # @param {String} checkout_session_id - The unique identifier for the CheckoutSession.
145
+ # @param {Object} payload - The payload for the request. This should include the fields that need to be updated.
146
+ # @param {Object} headers - Optional headers for the request.
147
+ # @return [HTTPResponse] The response from the API call, which includes the updated details of the CheckoutSession.
148
+ def update_checkout_session(checkout_session_id, payload, headers: {})
149
+ api_call("#{Constants::CHECKOUT_SESSION_URL}/#{checkout_session_id}", Constants::PATCH, payload: payload, headers: headers)
150
+ end
151
+
152
+ # API to complete a Checkout Session
153
+ # Confirms the completion of buyer checkout.
154
+ # @see https://developer.amazon.com/docs/amazon-pay-api-v2/checkout-session.html#complete-checkout-session
155
+ # @param {String} checkout_session_id - The unique identifier for the CheckoutSession.
156
+ # @param {Object} payload - The payload for the request, typically including fields like chargeAmount, currencyCode, etc.
157
+ # @param {Object} headers - Optional headers for the request.
158
+ # @return [HTTPResponse] The response from the API call, which confirms the completion of the checkout process.
159
+ def complete_checkout_session(checkout_session_id, payload, headers: {})
160
+ api_call("#{Constants::CHECKOUT_SESSION_URL}/#{checkout_session_id}/complete", Constants::POST, payload: payload, headers: headers)
161
+ end
162
+
163
+ # API to finalize a Checkout Session
164
+ # Finalizes the checkout process by confirming the payment and completing the session.
165
+ # @see https://developer.amazon.com/docs/amazon-pay-api-v2/checkout-session.html#finalize-checkout-session
166
+ # @param {String} checkout_session_id - The unique ID of the checkout session that needs to be finalized.
167
+ # @param {Object} payload - The payload for the request, typically including payment confirmation details.
168
+ # @param {Object} headers - Optional headers for the request, such as authorization tokens or custom headers.
169
+ # @return [HTTPResponse] The response from the API call, indicating the success or failure of the checkout finalization.
170
+ def finalize_checkout_session(checkout_session_id, payload, headers: {})
171
+ api_call("#{Constants::CHECKOUT_SESSION_URL}/#{checkout_session_id}/finalize", Constants::POST, payload: payload, headers: headers)
172
+ end
173
+
174
+ # API to retrieve a Charge Permission object
175
+ # Fetches details of a Charge Permission, which is associated with a Checkout Session.
176
+ # @see https://developer.amazon.com/docs/amazon-pay-api-v2/charge-permission.html#get-charge-permission
177
+ # @param {String} charge_permission_id - The unique identifier for the Charge Permission.
178
+ # @param {Object} headers - Optional headers for the request.
179
+ # @return [HTTPResponse] The response from the API call, including the details of the Charge Permission.
180
+ def get_charge_permission(charge_permission_id, headers: {})
181
+ api_call("#{Constants::CHARGE_PERMISSIONS_URL}/#{charge_permission_id}", Constants::GET, headers: headers)
182
+ end
183
+
184
+ # API to update a Charge Permission object
185
+ # Updates a previously created Charge Permission with new information.
186
+ # @see https://developer.amazon.com/docs/amazon-pay-api-v2/charge-permission.html#update-charge-permission
187
+ # @param {String} charge_permission_id - The unique identifier for the Charge Permission.
188
+ # @param {Object} payload - The payload for the request. This should include the fields that need to be updated.
189
+ # @param {Object} headers - Optional headers for the request.
190
+ # @return [HTTPResponse] The response from the API call, including the updated details of the Charge Permission.
191
+ def update_charge_permission(charge_permission_id, payload, headers: {})
192
+ api_call("#{Constants::CHARGE_PERMISSIONS_URL}/#{charge_permission_id}", Constants::PATCH, payload: payload, headers: headers)
193
+ end
194
+
195
+ # API to close a Charge Permission object
196
+ # Closes a Charge Permission, preventing further charges.
197
+ # @see https://developer.amazon.com/docs/amazon-pay-api-v2/charge-permission.html#close-charge-permission
198
+ # @param {String} charge_permission_id - The unique identifier for the Charge Permission.
199
+ # @param {Object} payload - The payload for the request, typically including a reason for closure.
200
+ # @param {Object} headers - Optional headers for the request.
201
+ # @return [HTTPResponse] The response from the API call, confirming the closure of the Charge Permission.
202
+ def close_charge_permission(charge_permission_id, payload, headers: {})
203
+ api_call("#{Constants::CHARGE_PERMISSIONS_URL}/#{charge_permission_id}/close", Constants::DELETE, payload: payload, headers: headers)
204
+ end
205
+
206
+ # API to create a new charge
207
+ # Initiates a new charge with the provided payment details.
208
+ # @see https://developer.amazon.com/docs/amazon-pay-api-v2/charge.html#create-charge
209
+ # @param {Object} payload - The payload containing payment details, such as the amount and currency.
210
+ # @param {Object} headers - Optional headers for the request, such as authorization tokens or custom headers.
211
+ # @return [HTTPResponse] The response from the API call, which includes details of the created charge.
212
+ def create_charge(payload, headers: {})
213
+ api_call(Constants::CHARGES_URL, Constants::POST, payload: payload, headers: headers)
214
+ end
215
+
216
+ # API to retrieve charge details
217
+ # Retrieves details of an existing charge using its unique charge ID.
218
+ # @see https://developer.amazon.com/docs/amazon-pay-api-v2/charge.html#get-charge
219
+ # @param {String} charge_id - The unique ID of the charge to retrieve.
220
+ # @param {Object} headers - Optional headers for the request, such as authorization tokens or custom headers.
221
+ # @return [HTTPResponse] The response from the API call, which includes details of the requested charge.
222
+ def get_charge(charge_id, headers: {})
223
+ api_call("#{Constants::CHARGES_URL}/#{charge_id}", Constants::GET, headers: headers)
224
+ end
225
+
226
+ # API to capture a charge
227
+ # Captures an authorized charge to collect the funds.
228
+ # @see https://developer.amazon.com/docs/amazon-pay-api-v2/charge.html#capture-charge
229
+ # @param {String} charge_id - The unique ID of the charge to capture.
230
+ # @param {Object} payload - The payload containing capture details, such as the amount to capture.
231
+ # @param {Object} headers - Optional headers for the request, such as authorization tokens or custom headers.
232
+ # @return [HTTPResponse] The response from the API call, which includes details of the captured charge.
233
+ def capture_charge(charge_id, payload, headers: {})
234
+ api_call("#{Constants::CHARGES_URL}/#{charge_id}/capture", Constants::POST, payload: payload, headers: headers)
235
+ end
236
+
237
+ # API to cancel a charge
238
+ # Cancels an existing charge, preventing it from being captured.
239
+ # @see https://developer.amazon.com/docs/amazon-pay-api-v2/charge.html#cancel-charge
240
+ # @param {String} charge_id - The unique ID of the charge to cancel.
241
+ # @param {Object} payload - The payload containing cancellation details.
242
+ # @param {Object} headers - Optional headers for the request, such as authorization tokens or custom headers.
243
+ # @return [HTTPResponse] The response from the API call, which confirms the cancellation of the charge.
244
+ def cancel_charge(charge_id, payload, headers: {})
245
+ api_call("#{Constants::CHARGES_URL}/#{charge_id}/cancel", Constants::DELETE, payload: payload, headers: headers)
246
+ end
247
+
248
+ # API to create a refund
249
+ # Initiates a new refund for a previously captured charge.
250
+ # @see https://developer.amazon.com/docs/amazon-pay-api-v2/refund.html#create-refund
251
+ # @param {Object} payload - The payload containing refund details, such as the amount and currency.
252
+ # @param {Object} headers - Optional headers for the request, such as authorization tokens or custom headers.
253
+ # @return [HTTPResponse] The response from the API call, which includes details of the created refund.
254
+ def create_refund(payload, headers: {})
255
+ api_call(Constants::REFUNDS_URL, Constants::POST, payload: payload, headers: headers)
256
+ end
257
+
258
+ # API to retrieve refund details
259
+ # Retrieves details of an existing refund using its unique refund ID.
260
+ # @see https://developer.amazon.com/docs/amazon-pay-api-v2/refund.html#get-refund
261
+ # @param {String} refund_id - The unique ID of the refund to retrieve.
262
+ # @param {Object} headers - Optional headers for the request, such as authorization tokens or custom headers.
263
+ # @return [HTTPResponse] The response from the API call, which includes details of the requested refund.
264
+ def get_refund(refund_id, headers: {})
265
+ api_call("#{Constants::REFUNDS_URL}/#{refund_id}", Constants::GET, headers: headers)
266
+ end
267
+
268
+ # API to retrieve a list of reports
269
+ # Retrieves a list of reports based on the provided query parameters.
270
+ # @see https://developer.amazon.com/docs/amazon-pay-api-v2/reports.html#get-reports
271
+ # @param {Object} headers - Optional headers for the request, such as authorization tokens or custom headers.
272
+ # @param {Object} query_params - Query parameters to filter the reports, such as report type or processing status.
273
+ # @return [HTTPResponse] The response from the API call, which includes a list of reports matching the criteria.
274
+ def get_reports(headers: {}, query_params: {})
275
+ api_call(Constants::REPORTS, Constants::GET, headers: headers, query_params: query_params)
276
+ end
277
+
278
+ # API to retrieve a specific report by ID
279
+ # Retrieves details of a specific report using its unique report ID.
280
+ # @see https://developer.amazon.com/docs/amazon-pay-api-v2/reports.html#get-report-by-id
281
+ # @param {String} report_id - The unique ID of the report to retrieve.
282
+ # @param {Object} headers - Optional headers for the request, such as authorization tokens or custom headers.
283
+ # @return [HTTPResponse] The response from the API call, which includes details of the requested report.
284
+ def get_report_by_id(report_id, headers: {})
285
+ api_call("#{Constants::REPORTS}/#{report_id}", Constants::GET, headers: headers)
286
+ end
287
+
288
+ # API to create a new report
289
+ # Creates a new report based on the provided payload.
290
+ # @see https://developer.amazon.com/docs/amazon-pay-api-v2/reports.html#create-report
291
+ # @param {Object} payload - The payload containing data required to generate the report.
292
+ # @param {Object} headers - Optional headers for the request, such as authorization tokens or custom headers.
293
+ # @return [HTTPResponse] The response from the API call, which includes confirmation and details of the created report.
294
+ def create_report(payload, headers: {})
295
+ api_call(Constants::REPORTS, Constants::POST, payload: payload, headers: headers)
296
+ end
297
+
298
+ # API to retrieve a specific report document by ID
299
+ # Retrieves the content of a specific report document using its unique report document ID.
300
+ # @see https://developer.amazon.com/docs/amazon-pay-api-v2/reports.html#get-report-document
301
+ # @param {String} report_document_id - The unique ID of the report document to retrieve.
302
+ # @param {Object} headers - Optional headers for the request, such as authorization tokens or custom headers.
303
+ # @return [HTTPResponse] The response from the API call, which includes the content of the requested report document.
304
+ def get_report_document(report_document_id, headers: {})
305
+ api_call("#{Constants::REPORT_DOCUMENTS}/#{report_document_id}", Constants::GET, headers: headers)
306
+ end
307
+
308
+ # API to retrieve a list of report schedules
309
+ # Retrieves a list of report schedules based on the provided query parameters.
310
+ # @see https://developer.amazon.com/docs/amazon-pay-api-v2/reports.html#get-report-schedules
311
+ # @param {Object} headers - Optional headers for the request, such as authorization tokens or custom headers.
312
+ # @param {Object} query_params - Query parameters to filter the report schedules, such as schedule type or status.
313
+ # @return [HTTPResponse] The response from the API call, which includes a list of report schedules matching the criteria.
314
+ def get_report_schedules(headers: {}, query_params: {})
315
+ api_call(Constants::REPORT_SCHEDULES, Constants::GET, headers: headers, query_params: query_params)
316
+ end
317
+
318
+ # API to retrieve a specific report schedule by ID
319
+ # Retrieves details of a specific report schedule using its unique report schedule ID.
320
+ # @see https://developer.amazon.com/docs/amazon-pay-api-v2/reports.html#get-report-schedule-by-id
321
+ # @param {String} report_schedule_id - The unique ID of the report schedule to retrieve.
322
+ # @param {Object} headers - Optional headers for the request, such as authorization tokens or custom headers.
323
+ # @return [HTTPResponse] The response from the API call, which includes details of the requested report schedule.
324
+ def get_report_schedule_by_id(report_schedule_id, headers: {})
325
+ api_call("#{Constants::REPORT_SCHEDULES}/#{report_schedule_id}", Constants::GET, headers: headers)
326
+ end
327
+
328
+ # API to create a new report schedule
329
+ # Creates a new report schedule based on the provided payload.
330
+ # @see https://developer.amazon.com/docs/amazon-pay-api-v2/reports.html#create-report-schedule
331
+ # @param {Object} payload - The payload containing data required to set up the report schedule.
332
+ # @param {Object} headers - Optional headers for the request, such as authorization tokens or custom headers.
333
+ # @return [HTTPResponse] The response from the API call, which includes confirmation and details of the created report schedule.
334
+ def create_report_schedule(payload, headers: {}, query_params: {})
335
+ api_call(Constants::REPORT_SCHEDULES, Constants::POST, payload: payload, headers: headers, query_params: query_params)
336
+ end
337
+
338
+ # API to cancel an existing report schedule by ID
339
+ # Cancels a specific report schedule using its unique report schedule ID.
340
+ # @see https://developer.amazon.com/docs/amazon-pay-api-v2/reports.html#cancel-report-schedule
341
+ # @param {String} report_schedule_id - The unique ID of the report schedule to cancel.
342
+ # @param {Object} headers - Optional headers for the request, such as authorization tokens or custom headers.
343
+ # @return [HTTPResponse] The response from the API call, which includes confirmation of the cancellation.
344
+ def cancel_report_schedule(report_schedule_id, headers: {})
345
+ api_call("#{Constants::REPORT_SCHEDULES}/#{report_schedule_id}", Constants::DELETE, headers: headers)
346
+ end
347
+
348
+ # API to retrieve a list of disbursements
349
+ # Retrieves a list of disbursements based on the provided query parameters.
350
+ # @see https://developer.amazon.com/docs/amazon-pay-api-v2/reports.html#get-disbursements
351
+ # @param {Object} headers - Optional headers for the request, such as authorization tokens or custom headers.
352
+ # @param {Object} query_params - Query parameters to filter the disbursements, such as date range or status.
353
+ # @return [HTTPResponse] The response from the API call, which includes a list of disbursements matching the criteria.
354
+ def get_disbursements(headers: {}, query_params: {})
355
+ api_call(Constants::DISBURSEMENTS, Constants::GET, headers: headers, query_params: query_params)
356
+ end
102
357
  end
@@ -1,8 +1,8 @@
1
1
  require 'net/http'
2
2
 
3
3
  module Constants
4
- SDK_TYPE = "MerchantOnboarding-Ruby".freeze
5
- SDK_VERSION = "1.0.0".freeze
4
+ SDK_TYPE = "amazon-pay-api-sdk-ruby".freeze
5
+ SDK_VERSION = "1.2.0".freeze
6
6
  API_VERSION = "v2".freeze
7
7
  API_ENDPOINTS = {
8
8
  'na' => 'pay-api.amazon.com',
@@ -32,11 +32,22 @@ 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
49
+ REPORTS = 'reports'.freeze
50
+ REPORT_SCHEDULES = 'report-schedules'.freeze
51
+ REPORT_DOCUMENTS = 'report-documents'.freeze
52
+ DISBURSEMENTS = 'disbursements'.freeze
42
53
  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.0.0
4
+ version: 1.2.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-05 00:00:00.000000000 Z
11
+ date: 2024-09-06 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.10
73
+ rubygems_version: 3.5.4
74
74
  signing_key:
75
75
  specification_version: 4
76
76
  summary: This is an AmazonPay Ruby SDK