amazon-pay-api-sdk-ruby 1.1.0 → 2.0.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 +312 -29
- data/lib/{amazon_pay → amazon-pay-api-sdk-ruby}/client.rb +103 -2
- data/lib/amazon-pay-api-sdk-ruby/constants.rb +97 -0
- data/lib/amazon-pay-api-sdk-ruby/payment_service_provider_client.rb +48 -0
- data/lib/amazon-pay-api-sdk-ruby.rb +3 -0
- metadata +8 -7
- data/lib/amazon_pay/constants.rb +0 -49
- data/lib/amazon_pay.rb +0 -3
- /data/lib/{amazon_pay → amazon-pay-api-sdk-ruby}/client_helper.rb +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 439cdb07dc4f4d22baaf1d26710a1163cfedd565a6d56a5d0e61b0afdcc2c981
|
4
|
+
data.tar.gz: 358f1dfb78f49d1270dc4a457e5664959a40aae6dec6db51476ec6e57e926853
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e14bc560974f5c2dd0078f8b676bc9b41d7c0a02da6e9cce9fb6f2837f16ed2007261f307fffe2e5ec022813d5f8884a6783d49bbb300059717349afce8f488
|
7
|
+
data.tar.gz: 6181e925f7943ec0d8d89b9af328c0a89433b6ecadc897ac07d10451dd75f58fc17ef3843f4b853385e531d8581da7474496bf9199b970c8cac08a223b134133
|
data/README.md
CHANGED
@@ -5,7 +5,7 @@ This guide provides step-by-step instructions on how to use the Amazon Pay Clien
|
|
5
5
|
|
6
6
|
### Prerequisites
|
7
7
|
|
8
|
-
- Ruby installed on your system.
|
8
|
+
- Ruby (version 2.7.0 or later) installed on your system.
|
9
9
|
- `amazon-pay-api-sdk-ruby` gem installed or this source code has been imported in your project.
|
10
10
|
- Your `publicKeyId` & `privateKey.pem` file available.
|
11
11
|
|
@@ -22,6 +22,8 @@ gem 'amazon-pay-api-sdk-ruby'
|
|
22
22
|
bundle install
|
23
23
|
```
|
24
24
|
|
25
|
+
**Notice:** Those who may upgrade from 1.x.x to 2.0.0 or higher: You must change the require statement from: `require './lib/amazon_pay'` to `require './lib/amazon-pay-api-sdk-ruby'` or `require 'amazon_pay'` to `require 'amazon-pay-api-sdk-ruby'`
|
26
|
+
|
25
27
|
### Configuration
|
26
28
|
|
27
29
|
Create a configuration with your Amazon Pay credentials and region:
|
@@ -47,7 +49,7 @@ client = AmazonPayClient.new(config)
|
|
47
49
|
Define the payload and headers for the `create_merchant_account` API call:
|
48
50
|
|
49
51
|
```ruby
|
50
|
-
require '
|
52
|
+
require 'amazon-pay-api-sdk-ruby'
|
51
53
|
|
52
54
|
client = AmazonPayClient.new(config)
|
53
55
|
|
@@ -86,35 +88,17 @@ createMerchantAccountPayload = {
|
|
86
88
|
}
|
87
89
|
}
|
88
90
|
},
|
89
|
-
|
90
|
-
|
91
|
-
"personId": "BO1",
|
92
|
-
"personFullName": "ABC ABC",
|
93
|
-
"residentialAddress": {
|
94
|
-
"addressLine1": "122, ABC XYZ",
|
95
|
-
"addressLine2": "XYZ",
|
96
|
-
"city": "XYZ",
|
97
|
-
"stateOrRegion": "XYZ",
|
98
|
-
"postalCode": "123456",
|
99
|
-
"countryCode": "JP",
|
100
|
-
"phoneNumber": {
|
101
|
-
"countryCode": "123",
|
102
|
-
"number": "2062062061"
|
103
|
-
}
|
104
|
-
}
|
105
|
-
},
|
106
|
-
{
|
107
|
-
"personId": "BO2",
|
108
|
-
"personFullName": "ABC ABC",
|
91
|
+
"beneficiaryOwners": [{
|
92
|
+
"personFullName": "Rufus Rufus",
|
109
93
|
"residentialAddress": {
|
110
|
-
"addressLine1": "
|
111
|
-
"addressLine2": "
|
112
|
-
"city": "
|
113
|
-
"stateOrRegion": "
|
114
|
-
"postalCode": "
|
94
|
+
"addressLine1": "4-7, Sunny Mansion 203",
|
95
|
+
"addressLine2": "Boren Ave",
|
96
|
+
"city": "Chiryushi",
|
97
|
+
"stateOrRegion": "AICHI",
|
98
|
+
"postalCode": "4720021",
|
115
99
|
"countryCode": "JP",
|
116
100
|
"phoneNumber": {
|
117
|
-
"countryCode": "
|
101
|
+
"countryCode": "81",
|
118
102
|
"number": "2062062061"
|
119
103
|
}
|
120
104
|
}
|
@@ -205,9 +189,11 @@ merchantAccountClaimPayload = {
|
|
205
189
|
}
|
206
190
|
|
207
191
|
response = client.merchant_account_claim('XXXXXXXXX', merchantAccountClaimPayload, headers: {})
|
208
|
-
if response.code.to_i == 303
|
192
|
+
if response.code.to_i == 303 || response.code.to_i == 200
|
209
193
|
puts "Merchant Account Claim API Response:"
|
210
194
|
puts response.body
|
195
|
+
puts "Headers:"
|
196
|
+
puts response.to_hash.to_json
|
211
197
|
else
|
212
198
|
puts "Error: Merchant Account Claim API"
|
213
199
|
puts "Status: #{response.code}"
|
@@ -525,6 +511,32 @@ else
|
|
525
511
|
end
|
526
512
|
```
|
527
513
|
|
514
|
+
### Update Charge
|
515
|
+
**Please note that is API is supported only for PSPs (Payment Service Provider)**
|
516
|
+
|
517
|
+
```ruby
|
518
|
+
def payload = {
|
519
|
+
"statusDetails": {
|
520
|
+
"state": "Canceled",
|
521
|
+
"reasonCode": "ExpiredUnused"
|
522
|
+
}
|
523
|
+
}
|
524
|
+
|
525
|
+
def headers = {
|
526
|
+
"x-amz-pay-Idempotency-Key": SecureRandom.uuid
|
527
|
+
}
|
528
|
+
|
529
|
+
response = client.update_charge("S03-XXXXXX-XXXXXX-XXXXXX", payload, headers: headers)
|
530
|
+
if response.code.to_i == 200
|
531
|
+
puts "Update Charge API Response:"
|
532
|
+
puts response.body
|
533
|
+
else
|
534
|
+
puts "Error: Update Charge API"
|
535
|
+
puts "Status: #{response.code}"
|
536
|
+
puts response.body
|
537
|
+
end
|
538
|
+
```
|
539
|
+
|
528
540
|
### Capture Charge
|
529
541
|
|
530
542
|
```ruby
|
@@ -610,4 +622,275 @@ else
|
|
610
622
|
puts "Status: #{response.code}"
|
611
623
|
puts response.body
|
612
624
|
end
|
625
|
+
```
|
626
|
+
|
627
|
+
### Get Reports
|
628
|
+
|
629
|
+
```ruby
|
630
|
+
response = client.get_reports(query_params: {})
|
631
|
+
if response.code.to_i == 200
|
632
|
+
puts "Get Reports Response:"
|
633
|
+
puts response.body
|
634
|
+
else
|
635
|
+
puts "Error: Get Reports API"
|
636
|
+
puts "Status: #{response.code}"
|
637
|
+
puts response.body
|
638
|
+
end
|
639
|
+
```
|
640
|
+
|
641
|
+
### Get Report By Id
|
642
|
+
|
643
|
+
```ruby
|
644
|
+
def report_id = "123456789"
|
645
|
+
response = client.get_report_by_id(report_id, headers: {})
|
646
|
+
if response.code.to_i == 200
|
647
|
+
puts "Get Report By Id Response:"
|
648
|
+
puts response.body
|
649
|
+
else
|
650
|
+
puts "Error: Get Report By Id API"
|
651
|
+
puts "Status: #{response.code}"
|
652
|
+
puts response.body
|
653
|
+
end
|
654
|
+
```
|
655
|
+
|
656
|
+
### Create Report
|
657
|
+
|
658
|
+
```ruby
|
659
|
+
def create_report_payload = {
|
660
|
+
"reportType": "_GET_FLAT_FILE_OFFAMAZONPAYMENTS_SANDBOX_SETTLEMENT_DATA_",
|
661
|
+
"startTime": "20240810T000000Z",
|
662
|
+
"endTime": "20240815T000000Z"
|
663
|
+
}
|
664
|
+
response = client.create_report(create_report_payload, headers: {"x-amz-pay-Idempotency-Key": SecureRandom.uuid})
|
665
|
+
if response.code.to_i == 201
|
666
|
+
puts "Create Report Response:"
|
667
|
+
puts response.body
|
668
|
+
else
|
669
|
+
puts "Error: Create Report API"
|
670
|
+
puts "Status: #{response.code}"
|
671
|
+
puts response.body
|
672
|
+
end
|
673
|
+
```
|
674
|
+
|
675
|
+
### Get Report Document
|
676
|
+
|
677
|
+
|
678
|
+
```ruby
|
679
|
+
def report_document_id = "123456789"
|
680
|
+
response = client.get_report_document(report_document_id, headers: {})
|
681
|
+
if response.code.to_i == 200
|
682
|
+
puts "Get Report Document Response:"
|
683
|
+
puts response.body
|
684
|
+
else
|
685
|
+
puts "Error: Get Report Document API"
|
686
|
+
puts "Status: #{response.code}"
|
687
|
+
puts response.body
|
688
|
+
end
|
689
|
+
```
|
690
|
+
|
691
|
+
### Get Report Schedules
|
692
|
+
|
693
|
+
```ruby
|
694
|
+
def query_params = {
|
695
|
+
"reportType": "_GET_FLAT_FILE_OFFAMAZONPAYMENTS_SANDBOX_SETTLEMENT_DATA_",
|
696
|
+
}
|
697
|
+
response = client.get_report_schedules(query_params: query_params, headers: {})
|
698
|
+
if response.code.to_i == 200
|
699
|
+
puts "Get Report Schedules Response:"
|
700
|
+
puts response.body
|
701
|
+
else
|
702
|
+
puts "Error: Get Report Schedules API"
|
703
|
+
puts "Status: #{response.code}"
|
704
|
+
puts response.body
|
705
|
+
end
|
706
|
+
```
|
707
|
+
|
708
|
+
### Get Report Schedule By ID
|
709
|
+
|
710
|
+
```ruby
|
711
|
+
def report_schedule_id = "123456789"
|
712
|
+
response = client.get_report_schedule_by_id(report_schedule_id, headers: {})
|
713
|
+
if response.code.to_i == 200
|
714
|
+
puts "Get Report Schedule By ID Response:"
|
715
|
+
puts response.body
|
716
|
+
else
|
717
|
+
puts "Error: Get Report Schedule By ID API"
|
718
|
+
puts "Status: #{response.code}"
|
719
|
+
puts response.body
|
720
|
+
end
|
721
|
+
```
|
722
|
+
|
723
|
+
### Create Report Schedule
|
724
|
+
|
725
|
+
```ruby
|
726
|
+
def create_report_schdule_payload = {
|
727
|
+
"reportType": "_GET_FLAT_FILE_OFFAMAZONPAYMENTS_SANDBOX_SETTLEMENT_DATA_",
|
728
|
+
"scheduleFrequency": "P1D",
|
729
|
+
"nextReportCreationTime": "20241001T000000Z"
|
730
|
+
}
|
731
|
+
response = client.create_report_schedule(create_report_schdule_payload, headers: {"x-amz-pay-Idempotency-Key": SecureRandom.uuid}, query_params: {})
|
732
|
+
if response.code.to_i == 201
|
733
|
+
puts "Create Report Schedule Response:"
|
734
|
+
puts response.body
|
735
|
+
else
|
736
|
+
puts "Error: Create Report Schedule API"
|
737
|
+
puts "Status: #{response.code}"
|
738
|
+
puts response.body
|
739
|
+
end
|
740
|
+
```
|
741
|
+
|
742
|
+
#### Cancel Report Schedule
|
743
|
+
|
744
|
+
```ruby
|
745
|
+
def report_schedule_id = "123456789"
|
746
|
+
response = client.cancel_report_schedule(report_schedule_id, headers: {})
|
747
|
+
if response.code.to_i == 200
|
748
|
+
puts "Cancel Report Schedule Schedule Response:"
|
749
|
+
puts response.body
|
750
|
+
else
|
751
|
+
puts "Error: Cancel Report Schedule Schedule API"
|
752
|
+
puts "Status: #{response.code}"
|
753
|
+
puts response.body
|
754
|
+
end
|
755
|
+
```
|
756
|
+
|
757
|
+
### Get Disbursements
|
758
|
+
|
759
|
+
```ruby
|
760
|
+
def query_params = {
|
761
|
+
"startTime": '20240810T000000Z',
|
762
|
+
"endTime": '20240815T000000Z'
|
763
|
+
"pageSize": "30",
|
764
|
+
"nextToken": ""
|
765
|
+
}
|
766
|
+
response = client.get_disbursements(query_params: {}, headers: {})
|
767
|
+
if response.code.to_i == 200
|
768
|
+
puts "Get Disbursements Response:"
|
769
|
+
puts response.body
|
770
|
+
else
|
771
|
+
puts "Error: Get Disbursements API"
|
772
|
+
puts "Status: #{response.code}"
|
773
|
+
puts response.body
|
774
|
+
end
|
775
|
+
```
|
776
|
+
|
777
|
+
### Create Dispute API
|
778
|
+
|
779
|
+
```ruby
|
780
|
+
creation_timestamp = Time.now.to_i
|
781
|
+
merchant_response_deadline = creation_timestamp + (14 * 24 * 60 * 60) # Adding 14 days
|
782
|
+
|
783
|
+
payload = {
|
784
|
+
"chargeId": "S03-XXXXXX-XXXXXX-XXXXXX",
|
785
|
+
"providerMetadata": {
|
786
|
+
"providerDisputeId": "AXXXXXXXXXX"
|
787
|
+
},
|
788
|
+
"disputeAmount": {
|
789
|
+
"amount": "1",
|
790
|
+
"currencyCode": "JPY"
|
791
|
+
},
|
792
|
+
"filingReason": Constants::DISPUTE_FILING_REASON[:PRODUCT_NOT_RECEIVED],
|
793
|
+
"creationTimestamp": creation_timestamp,
|
794
|
+
"statusDetails": {
|
795
|
+
"state": "ActionRequired"
|
796
|
+
},
|
797
|
+
"merchantResponseDeadline": merchant_response_deadline
|
798
|
+
}
|
799
|
+
|
800
|
+
def headers = {
|
801
|
+
"x-amz-pay-Idempotency-Key": SecureRandom.uuid
|
802
|
+
}
|
803
|
+
|
804
|
+
response = client.create_dispute(payload, headers: headers)
|
805
|
+
if response.code.to_i == 200
|
806
|
+
puts "Create Dispute API Response:"
|
807
|
+
puts response.body
|
808
|
+
else
|
809
|
+
puts "Error: Create Dispute API"
|
810
|
+
puts "Status: #{response.code}"
|
811
|
+
puts response.body
|
812
|
+
end
|
813
|
+
```
|
814
|
+
|
815
|
+
### Update Dispute API
|
816
|
+
|
817
|
+
```ruby
|
818
|
+
current_timestamp = Time.now.to_i
|
819
|
+
dispute_id = "S03-XXXXXX-XXXXXX-XXXXXX"
|
820
|
+
|
821
|
+
payload = {
|
822
|
+
"statusDetails": {
|
823
|
+
"resolution": Constants::DISPUTE_RESOLUTION[:MERCHANT_WON],
|
824
|
+
"state": Constants::DISPUTE_STATE[:RESOLVED],
|
825
|
+
"reasonCode": Constants::DISPUTE_REASON_CODE[:MERCHANT_ACCEPTED_DISPUTE],
|
826
|
+
"reasonDescription": "Merchant accepted the dispute request"
|
827
|
+
},
|
828
|
+
"closureTimestamp": current_timestamp
|
829
|
+
}
|
830
|
+
|
831
|
+
def headers = {
|
832
|
+
"x-amz-pay-Idempotency-Key": SecureRandom.uuid
|
833
|
+
}
|
834
|
+
|
835
|
+
response = client.update_dispute(dispute_id, payload, headers: {})
|
836
|
+
if response.code.to_i == 200
|
837
|
+
puts "Update Dispute API Response:"
|
838
|
+
puts response.body
|
839
|
+
else
|
840
|
+
puts "Error: Update Dispute API"
|
841
|
+
puts "Status: #{response.code}"
|
842
|
+
puts response.body
|
843
|
+
end
|
844
|
+
```
|
845
|
+
|
846
|
+
### Contest Dispute API
|
847
|
+
|
848
|
+
```ruby
|
849
|
+
current_timestamp = Time.now.to_i
|
850
|
+
dispute_id = "S03-XXXXXX-XXXXXX-XXXXXX"
|
851
|
+
|
852
|
+
payload = {
|
853
|
+
"merchantEvidences": [
|
854
|
+
"evidenceType": "TrackingNumber",
|
855
|
+
"fileId": "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxx",
|
856
|
+
"evidenceText": "raw text supporting merchant evidence"
|
857
|
+
]
|
858
|
+
}
|
859
|
+
|
860
|
+
def headers = {
|
861
|
+
"x-amz-pay-Idempotency-Key": SecureRandom.uuid
|
862
|
+
}
|
863
|
+
|
864
|
+
response = client.contest_dispute(dispute_id, payload, headers: {})
|
865
|
+
if response.code.to_i == 200
|
866
|
+
puts "Contest Dispute API Response:"
|
867
|
+
puts response.body
|
868
|
+
else
|
869
|
+
puts "Error: Contest Dispute API"
|
870
|
+
puts "Status: #{response.code}"
|
871
|
+
puts response.body
|
872
|
+
end
|
873
|
+
```
|
874
|
+
|
875
|
+
### File Upload API
|
876
|
+
|
877
|
+
```ruby
|
878
|
+
payload = {
|
879
|
+
"type": "jpg",
|
880
|
+
"purpose": "disputeEvidence"
|
881
|
+
}
|
882
|
+
|
883
|
+
def headers = {
|
884
|
+
"x-amz-pay-Idempotency-Key": SecureRandom.uuid
|
885
|
+
}
|
886
|
+
|
887
|
+
response = client.upload_file(payload, headers: headers)
|
888
|
+
if response.code.to_i == 200
|
889
|
+
puts "Upload File API Response:"
|
890
|
+
puts response.body
|
891
|
+
else
|
892
|
+
puts "Error: Upload File API"
|
893
|
+
puts "Status: #{response.code}"
|
894
|
+
puts response.body
|
895
|
+
end
|
613
896
|
```
|
@@ -1,9 +1,10 @@
|
|
1
1
|
require 'net/http'
|
2
2
|
require_relative 'client_helper'
|
3
3
|
require_relative 'constants'
|
4
|
+
require_relative 'payment_service_provider_client'
|
4
5
|
|
5
6
|
# AmazonPayClient class provides methods to interact with Amazon Pay API
|
6
|
-
class AmazonPayClient
|
7
|
+
class AmazonPayClient include PaymentServiceProviderClient
|
7
8
|
|
8
9
|
# Initialize the client with configuration settings
|
9
10
|
def initialize(config)
|
@@ -47,7 +48,6 @@ class AmazonPayClient
|
|
47
48
|
|
48
49
|
# Increment the retry counter
|
49
50
|
retries += 1
|
50
|
-
print "Retrying\n"
|
51
51
|
# Raise an exception to force a retry
|
52
52
|
raise "Transient error: #{response.code}" # Force retry
|
53
53
|
end
|
@@ -224,6 +224,18 @@ class AmazonPayClient
|
|
224
224
|
api_call("#{Constants::CHARGES_URL}/#{charge_id}", Constants::GET, headers: headers)
|
225
225
|
end
|
226
226
|
|
227
|
+
# API to retrieve charge details.
|
228
|
+
# The updateCharge operation is used to update the charge status of any PSP (Payment Service Provider) processed payment method (PPM) transactions.
|
229
|
+
# Please note that is API is supported only for PSPs (Payment Service Provider)
|
230
|
+
# @see https://developer.amazon.com/docs/amazon-pay-apis/charge.html#update-charge
|
231
|
+
# @param {String} charge_id - The unique ID of the charge to update.
|
232
|
+
# @param {Object} payload - The payload containing statusDetails.
|
233
|
+
# @param {Object} headers - Optional headers for the request, such as x-amz-pay-idempotency-key, authorization tokens or custom headers.
|
234
|
+
# @return [HTTPResponse] The response from the API call, which includes details of the requested charge.
|
235
|
+
def update_charge(charge_id, payload, headers: {})
|
236
|
+
api_call("#{Constants::CHARGES_URL}/#{charge_id}", Constants::PATCH, payload: payload, headers: headers)
|
237
|
+
end
|
238
|
+
|
227
239
|
# API to capture a charge
|
228
240
|
# Captures an authorized charge to collect the funds.
|
229
241
|
# @see https://developer.amazon.com/docs/amazon-pay-api-v2/charge.html#capture-charge
|
@@ -266,4 +278,93 @@ class AmazonPayClient
|
|
266
278
|
api_call("#{Constants::REFUNDS_URL}/#{refund_id}", Constants::GET, headers: headers)
|
267
279
|
end
|
268
280
|
|
281
|
+
# API to retrieve a list of reports
|
282
|
+
# Retrieves a list of reports based on the provided query parameters.
|
283
|
+
# @see https://developer.amazon.com/docs/amazon-pay-api-v2/reports.html#get-reports
|
284
|
+
# @param {Object} headers - Optional headers for the request, such as authorization tokens or custom headers.
|
285
|
+
# @param {Object} query_params - Query parameters to filter the reports, such as report type or processing status.
|
286
|
+
# @return [HTTPResponse] The response from the API call, which includes a list of reports matching the criteria.
|
287
|
+
def get_reports(headers: {}, query_params: {})
|
288
|
+
api_call(Constants::REPORTS, Constants::GET, headers: headers, query_params: query_params)
|
289
|
+
end
|
290
|
+
|
291
|
+
# API to retrieve a specific report by ID
|
292
|
+
# Retrieves details of a specific report using its unique report ID.
|
293
|
+
# @see https://developer.amazon.com/docs/amazon-pay-api-v2/reports.html#get-report-by-id
|
294
|
+
# @param {String} report_id - The unique ID of the report to retrieve.
|
295
|
+
# @param {Object} headers - Optional headers for the request, such as authorization tokens or custom headers.
|
296
|
+
# @return [HTTPResponse] The response from the API call, which includes details of the requested report.
|
297
|
+
def get_report_by_id(report_id, headers: {})
|
298
|
+
api_call("#{Constants::REPORTS}/#{report_id}", Constants::GET, headers: headers)
|
299
|
+
end
|
300
|
+
|
301
|
+
# API to create a new report
|
302
|
+
# Creates a new report based on the provided payload.
|
303
|
+
# @see https://developer.amazon.com/docs/amazon-pay-api-v2/reports.html#create-report
|
304
|
+
# @param {Object} payload - The payload containing data required to generate the report.
|
305
|
+
# @param {Object} headers - Optional headers for the request, such as authorization tokens or custom headers.
|
306
|
+
# @return [HTTPResponse] The response from the API call, which includes confirmation and details of the created report.
|
307
|
+
def create_report(payload, headers: {})
|
308
|
+
api_call(Constants::REPORTS, Constants::POST, payload: payload, headers: headers)
|
309
|
+
end
|
310
|
+
|
311
|
+
# API to retrieve a specific report document by ID
|
312
|
+
# Retrieves the content of a specific report document using its unique report document ID.
|
313
|
+
# @see https://developer.amazon.com/docs/amazon-pay-api-v2/reports.html#get-report-document
|
314
|
+
# @param {String} report_document_id - The unique ID of the report document to retrieve.
|
315
|
+
# @param {Object} headers - Optional headers for the request, such as authorization tokens or custom headers.
|
316
|
+
# @return [HTTPResponse] The response from the API call, which includes the content of the requested report document.
|
317
|
+
def get_report_document(report_document_id, headers: {})
|
318
|
+
api_call("#{Constants::REPORT_DOCUMENTS}/#{report_document_id}", Constants::GET, headers: headers)
|
319
|
+
end
|
320
|
+
|
321
|
+
# API to retrieve a list of report schedules
|
322
|
+
# Retrieves a list of report schedules based on the provided query parameters.
|
323
|
+
# @see https://developer.amazon.com/docs/amazon-pay-api-v2/reports.html#get-report-schedules
|
324
|
+
# @param {Object} headers - Optional headers for the request, such as authorization tokens or custom headers.
|
325
|
+
# @param {Object} query_params - Query parameters to filter the report schedules, such as schedule type or status.
|
326
|
+
# @return [HTTPResponse] The response from the API call, which includes a list of report schedules matching the criteria.
|
327
|
+
def get_report_schedules(headers: {}, query_params: {})
|
328
|
+
api_call(Constants::REPORT_SCHEDULES, Constants::GET, headers: headers, query_params: query_params)
|
329
|
+
end
|
330
|
+
|
331
|
+
# API to retrieve a specific report schedule by ID
|
332
|
+
# Retrieves details of a specific report schedule using its unique report schedule ID.
|
333
|
+
# @see https://developer.amazon.com/docs/amazon-pay-api-v2/reports.html#get-report-schedule-by-id
|
334
|
+
# @param {String} report_schedule_id - The unique ID of the report schedule to retrieve.
|
335
|
+
# @param {Object} headers - Optional headers for the request, such as authorization tokens or custom headers.
|
336
|
+
# @return [HTTPResponse] The response from the API call, which includes details of the requested report schedule.
|
337
|
+
def get_report_schedule_by_id(report_schedule_id, headers: {})
|
338
|
+
api_call("#{Constants::REPORT_SCHEDULES}/#{report_schedule_id}", Constants::GET, headers: headers)
|
339
|
+
end
|
340
|
+
|
341
|
+
# API to create a new report schedule
|
342
|
+
# Creates a new report schedule based on the provided payload.
|
343
|
+
# @see https://developer.amazon.com/docs/amazon-pay-api-v2/reports.html#create-report-schedule
|
344
|
+
# @param {Object} payload - The payload containing data required to set up the report schedule.
|
345
|
+
# @param {Object} headers - Optional headers for the request, such as authorization tokens or custom headers.
|
346
|
+
# @return [HTTPResponse] The response from the API call, which includes confirmation and details of the created report schedule.
|
347
|
+
def create_report_schedule(payload, headers: {}, query_params: {})
|
348
|
+
api_call(Constants::REPORT_SCHEDULES, Constants::POST, payload: payload, headers: headers, query_params: query_params)
|
349
|
+
end
|
350
|
+
|
351
|
+
# API to cancel an existing report schedule by ID
|
352
|
+
# Cancels a specific report schedule using its unique report schedule ID.
|
353
|
+
# @see https://developer.amazon.com/docs/amazon-pay-api-v2/reports.html#cancel-report-schedule
|
354
|
+
# @param {String} report_schedule_id - The unique ID of the report schedule to cancel.
|
355
|
+
# @param {Object} headers - Optional headers for the request, such as authorization tokens or custom headers.
|
356
|
+
# @return [HTTPResponse] The response from the API call, which includes confirmation of the cancellation.
|
357
|
+
def cancel_report_schedule(report_schedule_id, headers: {})
|
358
|
+
api_call("#{Constants::REPORT_SCHEDULES}/#{report_schedule_id}", Constants::DELETE, headers: headers)
|
359
|
+
end
|
360
|
+
|
361
|
+
# API to retrieve a list of disbursements
|
362
|
+
# Retrieves a list of disbursements based on the provided query parameters.
|
363
|
+
# @see https://developer.amazon.com/docs/amazon-pay-api-v2/reports.html#get-disbursements
|
364
|
+
# @param {Object} headers - Optional headers for the request, such as authorization tokens or custom headers.
|
365
|
+
# @param {Object} query_params - Query parameters to filter the disbursements, such as date range or status.
|
366
|
+
# @return [HTTPResponse] The response from the API call, which includes a list of disbursements matching the criteria.
|
367
|
+
def get_disbursements(headers: {}, query_params: {})
|
368
|
+
api_call(Constants::DISBURSEMENTS, Constants::GET, headers: headers, query_params: query_params)
|
369
|
+
end
|
269
370
|
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
module Constants
|
4
|
+
SDK_TYPE = "amazon-pay-api-sdk-ruby".freeze
|
5
|
+
SDK_VERSION = "2.0.0".freeze
|
6
|
+
API_VERSION = "v2".freeze
|
7
|
+
API_ENDPOINTS = {
|
8
|
+
'na' => 'pay-api.amazon.com',
|
9
|
+
'eu' => 'pay-api.amazon.eu',
|
10
|
+
'jp' => 'pay-api.amazon.jp'
|
11
|
+
}.freeze
|
12
|
+
METHOD_TYPES = {
|
13
|
+
'GET' => Net::HTTP::Get,
|
14
|
+
'POST' => Net::HTTP::Post,
|
15
|
+
'PUT' => Net::HTTP::Put,
|
16
|
+
'PATCH' => Net::HTTP::Patch,
|
17
|
+
'DELETE' => Net::HTTP::Delete
|
18
|
+
}.freeze
|
19
|
+
HASH_ALGORITHM = "SHA256".freeze
|
20
|
+
HTTPS = 'https'.freeze
|
21
|
+
AMAZON_SIGNATURE_ALGORITHM = "AMZN-PAY-RSASSA-PSS-V2".freeze
|
22
|
+
AUTHORIZATION = 'authorization'.freeze
|
23
|
+
ACCEPT = 'accept'.freeze
|
24
|
+
CONTENT_TYPE = 'content-type'.freeze
|
25
|
+
APPLICATION_JSON = 'application/json'.freeze
|
26
|
+
X_AMZ_PAY_REGION = 'x-amz-pay-region'.freeze
|
27
|
+
X_AMZ_PAY_DATE = 'x-amz-pay-date'.freeze
|
28
|
+
X_AMZ_PAY_HOST = 'x-amz-pay-host'.freeze
|
29
|
+
CONTENT_LENGTH = 'content-length'.freeze
|
30
|
+
X_AMZ_PAY_SDK_TYPE = 'x-amz-pay-sdk-type'.freeze
|
31
|
+
X_AMZ_PAY_SDK_VERSION = 'x-amz-pay-sdk-version'.freeze
|
32
|
+
LIVE = 'LIVE-'
|
33
|
+
SANDBOX = 'SANDBOX-'
|
34
|
+
MERCHANT_ACCOUNTS_BASE_URL = 'merchantAccounts'.freeze
|
35
|
+
GET = 'GET'.freeze
|
36
|
+
POST = 'POST'.freeze
|
37
|
+
PATCH = 'PATCH'.freeze
|
38
|
+
DELETE = 'DELETE'.freeze
|
39
|
+
MAX_RETRIES = 3.freeze
|
40
|
+
BACKOFF_TIMES = [1, 2, 4].freeze # Define backoff times for retries
|
41
|
+
RETRYABLE_ERROR_CODES = [408, 429, 500, 502, 503, 504].freeze
|
42
|
+
HTTP_OK = '200'
|
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
|
53
|
+
DISPUTE_URLS = 'disputes'.freeze
|
54
|
+
FILES_URLS = 'files'.freeze
|
55
|
+
DISPUTE_FILING_REASON = {
|
56
|
+
PRODUCT_NOT_RECEIVED: "ProductNotReceived",
|
57
|
+
PRODUCT_UNACCEPTABLE: "ProductUnacceptable",
|
58
|
+
PRODUCT_NO_LONGER_NEEDED: "ProductNoLongerNeeded",
|
59
|
+
CREDIT_NOT_PROCESSED: "CreditNotProcessed",
|
60
|
+
OVERCHARGED: "Overcharged",
|
61
|
+
DUPLICATE_CHARGE: "DuplicateCharge",
|
62
|
+
SUBSCRIPTION_CANCELLED: "SubscriptionCancelled",
|
63
|
+
UNRECOGNIZED: "Unrecognized",
|
64
|
+
FRAUDULENT: "Fraudulent",
|
65
|
+
OTHER: "Other"
|
66
|
+
}.freeze
|
67
|
+
DISPUTE_REASON_CODE = {
|
68
|
+
MERCHANT_RESPONSE_REQUIRED: "MerchantResponseRequired",
|
69
|
+
MERCHANT_ADDITIONAL_EVIDENCES_REQUIRED: "MerchantAdditionalEvidencesRequired",
|
70
|
+
BUYER_ADDITIONAL_EVIDENCES_REQUIRED: "BuyerAdditionalEvidencesRequired",
|
71
|
+
MERCHANT_ACCEPTED_DISPUTE: "MerchantAcceptedDispute",
|
72
|
+
MERCHANT_RESPONSE_DEADLINE_EXPIRED: "MerchantResponseDeadlineExpired",
|
73
|
+
BUYER_CANCELLED: "BuyerCancelled",
|
74
|
+
INVESTIGATOR_RESOLVED: "InvestigatorResolved",
|
75
|
+
AUTO_RESOLVED: "AutoResolved",
|
76
|
+
CHARGEBACK_FILED: "ChargebackFiled"
|
77
|
+
}.freeze
|
78
|
+
DISPUTE_RESOLUTION = {
|
79
|
+
BUYER_WON: "BuyerWon",
|
80
|
+
MERCHANT_WON: "MerchantWon",
|
81
|
+
NO_FAULT: "NoFault"
|
82
|
+
}.freeze
|
83
|
+
DISPUTE_STATE = {
|
84
|
+
UNDER_REVIEW: "UnderReview",
|
85
|
+
ACTION_REQUIRED: "ActionRequired",
|
86
|
+
RESOLVED: "Resolved",
|
87
|
+
CLOSED: "Closed"
|
88
|
+
}.freeze
|
89
|
+
EVIDENCE_TYPE = {
|
90
|
+
PRODUCT_DESCRIPTION: "ProductDescription",
|
91
|
+
RECEIPT: "Receipt",
|
92
|
+
CANCELLATION_POLICY: "CancellationPolicy",
|
93
|
+
CUSTOMER_SIGNATURE: "CustomerSignature",
|
94
|
+
TRACKING_NUMBER: "TrackingNumber",
|
95
|
+
OTHER: "Other"
|
96
|
+
}.freeze
|
97
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module PaymentServiceProviderClient
|
2
|
+
# API to create dispute.
|
3
|
+
# The createDispute operation is used to notify Amazon of a newly created chargeback dispute by a buyer on a
|
4
|
+
# transaction processed by the PSP (Payment Service Provider), ensuring the dispute is properly accounted for in the Amazon Pay systems.
|
5
|
+
# @see https://developer.amazon.com/docs/amazon-pay-apis/dispute.html/#create-dispute
|
6
|
+
# @param {Object} payload - The payload containing statusDetails.
|
7
|
+
# @param {Object} headers - Requires : x-amz-pay-idempotency-key, Optional headers for the request, such as authorization tokens or custom headers.
|
8
|
+
# @return [HTTPResponse] The response from the API call, which includes details of the dispute.
|
9
|
+
def create_dispute(payload, headers: {});
|
10
|
+
api_call(Constants::DISPUTE_URLS, Constants::POST, payload: payload, headers: headers)
|
11
|
+
end
|
12
|
+
|
13
|
+
# API to update dispute.
|
14
|
+
# The updateDispute operation is used to notify Amazon of the closure status of a chargeback dispute initiated by a
|
15
|
+
# buyer for orders processed by a partner PSP (Payment Service Provider), ensuring proper accounting within the Amazon systems.
|
16
|
+
# @see https://developer.amazon.com/docs/amazon-pay-apis/dispute.html/#update-dispute
|
17
|
+
# @param {String} dispute_id - The unique ID of the dispute to retrieve.
|
18
|
+
# @param {Object} payload - The payload containing statusDetails.
|
19
|
+
# @param {Object} headers - Optional headers for the request, such as x-amz-pay-idempotency-key, authorization tokens or custom headers.
|
20
|
+
# @return [HTTPResponse] The response from the API call, which includes details of the dispute.
|
21
|
+
def update_dispute(dispute_id, payload, headers: {});
|
22
|
+
api_call("#{Constants::DISPUTE_URLS}/#{dispute_id}", Constants::PATCH, payload: payload, headers: headers)
|
23
|
+
end
|
24
|
+
|
25
|
+
# API to contest dispute.
|
26
|
+
# The contestDispute operation is used by the partner, on behalf of the merchant, to formally contest a dispute
|
27
|
+
# managed by Amazon, requiring the submission of necessary evidence files within the specified
|
28
|
+
# Dispute Window (11 days for Chargeback, 7 days for A-Z Claims).
|
29
|
+
# @see https://developer.amazon.com/docs/amazon-pay-apis/dispute.html/#contest-dispute
|
30
|
+
# @param {String} dispute_id - The unique ID of the dispute to retrieve.
|
31
|
+
# @param {Object} payload - The payload containing statusDetails.
|
32
|
+
# @param {Object} headers - Optional headers for the request, such as x-amz-pay-idempotency-key, authorization tokens or custom headers.
|
33
|
+
# @return [HTTPResponse] The response from the API call, which includes details of the dispute.
|
34
|
+
def contest_dispute(dispute_id, payload, headers: {});
|
35
|
+
api_call("#{Constants::DISPUTE_URLS}/#{dispute_id}/contest", Constants::POST, payload: payload, headers: headers)
|
36
|
+
end
|
37
|
+
|
38
|
+
# API to upload file.
|
39
|
+
# The uploadFile operation is utilised by PSPs (Payment Service Provider) to upload file-based evidence when a
|
40
|
+
# merchant contests a dispute, providing the necessary reference ID to the evidence file as part of
|
41
|
+
# the Update Dispute API process.
|
42
|
+
# @see https://developer.amazon.com/docs/amazon-pay-apis/file.html#upload-a-file
|
43
|
+
# @param {Object} headers - Requires : x-amz-pay-idempotency-key, Optional headers for the request, such as authorization tokens or custom headers.
|
44
|
+
# @return [HTTPResponse] The response from the API call, which includes details of the file.
|
45
|
+
def upload_file(payload, headers: {});
|
46
|
+
api_call(Constants::FILES_URLS, Constants::POST, payload: payload, headers: headers)
|
47
|
+
end
|
48
|
+
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:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- AmazonPay
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: base64
|
@@ -31,7 +31,7 @@ dependencies:
|
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '3.0'
|
34
|
-
type: :
|
34
|
+
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
@@ -46,10 +46,11 @@ extra_rdoc_files: []
|
|
46
46
|
files:
|
47
47
|
- LICENSE
|
48
48
|
- README.md
|
49
|
-
- lib/
|
50
|
-
- lib/
|
51
|
-
- lib/
|
52
|
-
- lib/
|
49
|
+
- lib/amazon-pay-api-sdk-ruby.rb
|
50
|
+
- lib/amazon-pay-api-sdk-ruby/client.rb
|
51
|
+
- lib/amazon-pay-api-sdk-ruby/client_helper.rb
|
52
|
+
- lib/amazon-pay-api-sdk-ruby/constants.rb
|
53
|
+
- lib/amazon-pay-api-sdk-ruby/payment_service_provider_client.rb
|
53
54
|
homepage: https://rubygems.org/gems/amazon-pay-api-sdk-ruby
|
54
55
|
licenses:
|
55
56
|
- Apache-2.0
|
data/lib/amazon_pay/constants.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'net/http'
|
2
|
-
|
3
|
-
module Constants
|
4
|
-
SDK_TYPE = "amazon-pay-api-sdk-ruby".freeze
|
5
|
-
SDK_VERSION = "1.1.0".freeze
|
6
|
-
API_VERSION = "v2".freeze
|
7
|
-
API_ENDPOINTS = {
|
8
|
-
'na' => 'pay-api.amazon.com',
|
9
|
-
'eu' => 'pay-api.amazon.eu',
|
10
|
-
'jp' => 'pay-api.amazon.jp'
|
11
|
-
}.freeze
|
12
|
-
METHOD_TYPES = {
|
13
|
-
'GET' => Net::HTTP::Get,
|
14
|
-
'POST' => Net::HTTP::Post,
|
15
|
-
'PUT' => Net::HTTP::Put,
|
16
|
-
'PATCH' => Net::HTTP::Patch,
|
17
|
-
'DELETE' => Net::HTTP::Delete
|
18
|
-
}.freeze
|
19
|
-
HASH_ALGORITHM = "SHA256".freeze
|
20
|
-
HTTPS = 'https'.freeze
|
21
|
-
AMAZON_SIGNATURE_ALGORITHM = "AMZN-PAY-RSASSA-PSS-V2".freeze
|
22
|
-
AUTHORIZATION = 'authorization'.freeze
|
23
|
-
ACCEPT = 'accept'.freeze
|
24
|
-
CONTENT_TYPE = 'content-type'.freeze
|
25
|
-
APPLICATION_JSON = 'application/json'.freeze
|
26
|
-
X_AMZ_PAY_REGION = 'x-amz-pay-region'.freeze
|
27
|
-
X_AMZ_PAY_DATE = 'x-amz-pay-date'.freeze
|
28
|
-
X_AMZ_PAY_HOST = 'x-amz-pay-host'.freeze
|
29
|
-
CONTENT_LENGTH = 'content-length'.freeze
|
30
|
-
X_AMZ_PAY_SDK_TYPE = 'x-amz-pay-sdk-type'.freeze
|
31
|
-
X_AMZ_PAY_SDK_VERSION = 'x-amz-pay-sdk-version'.freeze
|
32
|
-
LIVE = 'LIVE-'
|
33
|
-
SANDBOX = 'SANDBOX-'
|
34
|
-
MERCHANT_ACCOUNTS_BASE_URL = 'merchantAccounts'.freeze
|
35
|
-
GET = 'GET'.freeze
|
36
|
-
POST = 'POST'.freeze
|
37
|
-
PATCH = 'PATCH'.freeze
|
38
|
-
DELETE = 'DELETE'.freeze
|
39
|
-
MAX_RETRIES = 3.freeze
|
40
|
-
BACKOFF_TIMES = [1, 2, 4].freeze # Define backoff times for retries
|
41
|
-
RETRYABLE_ERROR_CODES = [408, 429, 500, 502, 503, 504].freeze
|
42
|
-
HTTP_OK = '200'
|
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
|
-
end
|
data/lib/amazon_pay.rb
DELETED
File without changes
|