Skip to content

Commit

Permalink
Version 1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Shangamesh T committed Sep 6, 2024
1 parent 9497802 commit 40e0018
Show file tree
Hide file tree
Showing 6 changed files with 374 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#### Version 1.2.0 - September 2024
- Added APIs for Reports.
- Included a README file with sample code for each API.

#### Version 1.1.0 - August 2024
- Added APIs for Buyer, CheckoutSession, ChargePermission, Charge, and Refund.
- Implemented a utility for generating button signatures.
Expand Down
152 changes: 151 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ createMerchantAccountPayload = {
}
}
},
"beneficiaryOwners": [{
"beneficiaryOwners": [{
"personFullName": "Rufus Rufus",
"residentialAddress": {
"addressLine1": "4-7, Sunny Mansion 203",
Expand Down Expand Up @@ -595,3 +595,153 @@ else
puts response.body
end
```

### Get Reports

```ruby
response = client.get_reports(query_params: {})
if response.code.to_i == 200
puts "Get Reports Response:"
puts response.body
else
puts "Error: Get Reports API"
puts "Status: #{response.code}"
puts response.body
end
```

### Get Report By Id

```ruby
def report_id = "123456789"
response = client.get_report_by_id(report_id, headers: {})
if response.code.to_i == 200
puts "Get Report By Id Response:"
puts response.body
else
puts "Error: Get Report By Id API"
puts "Status: #{response.code}"
puts response.body
end
```

### Create Report

```ruby
def create_report_payload = {
"reportType": "_GET_FLAT_FILE_OFFAMAZONPAYMENTS_SANDBOX_SETTLEMENT_DATA_",
"startTime": "20240810T000000Z",
"endTime": "20240815T000000Z"
}
response = client.create_report(create_report_payload, headers: {"x-amz-pay-Idempotency-Key": SecureRandom.uuid})
if response.code.to_i == 201
puts "Create Report Response:"
puts response.body
else
puts "Error: Create Report API"
puts "Status: #{response.code}"
puts response.body
end
```

### Get Report Document


```ruby
def report_document_id = "123456789"
response = client.get_report_document(report_document_id, headers: {})
if response.code.to_i == 200
puts "Get Report Document Response:"
puts response.body
else
puts "Error: Get Report Document API"
puts "Status: #{response.code}"
puts response.body
end
```

### Get Report Schedules

```ruby
def query_params = {
"reportType": "_GET_FLAT_FILE_OFFAMAZONPAYMENTS_SANDBOX_SETTLEMENT_DATA_",
}
response = client.get_report_schedules(query_params: query_params, headers: {})
if response.code.to_i == 200
puts "Get Report Schedules Response:"
puts response.body
else
puts "Error: Get Report Schedules API"
puts "Status: #{response.code}"
puts response.body
end
```

### Get Report Schedule By ID

```ruby
def report_schedule_id = "123456789"
response = client.get_report_schedule_by_id(report_schedule_id, headers: {})
if response.code.to_i == 200
puts "Get Report Schedule By ID Response:"
puts response.body
else
puts "Error: Get Report Schedule By ID API"
puts "Status: #{response.code}"
puts response.body
end
```

### Create Report Schedule

```ruby
def create_report_schdule_payload = {
"reportType": "_GET_FLAT_FILE_OFFAMAZONPAYMENTS_SANDBOX_SETTLEMENT_DATA_",
"scheduleFrequency": "P1D",
"nextReportCreationTime": "20241001T000000Z"
}
response = client.create_report_schedule(create_report_schdule_payload, headers: {"x-amz-pay-Idempotency-Key": SecureRandom.uuid}, query_params: {})
if response.code.to_i == 201
puts "Create Report Schedule Response:"
puts response.body
else
puts "Error: Create Report Schedule API"
puts "Status: #{response.code}"
puts response.body
end
```

#### Cancel Report Schedule

```ruby
def report_schedule_id = "123456789"
response = client.cancel_report_schedule(report_schedule_id, headers: {})
if response.code.to_i == 200
puts "Cancel Report Schedule Schedule Response:"
puts response.body
else
puts "Error: Cancel Report Schedule Schedule API"
puts "Status: #{response.code}"
puts response.body
end
```

### Get Disbursements

```ruby
def query_params = {
"startTime": '20240810T000000Z',
"endTime": '20240815T000000Z'
"pageSize": "30",
"nextToken": ""
}
response = client.get_disbursements(query_params: {}, headers: {})
if response.code.to_i == 200
puts "Get Disbursements Response:"
puts response.body
else
puts "Error: Get Disbursements API"
puts "Status: #{response.code}"
puts response.body
end
```
2 changes: 1 addition & 1 deletion amazon-pay-api-sdk-ruby.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ $:.push File.expand_path('../lib', __FILE__)

Gem::Specification.new do |s|
s.name = 'amazon-pay-api-sdk-ruby'
s.version = '1.1.0'
s.version = '1.2.0'
s.licenses = ['Apache-2.0']
s.summary = 'This is an AmazonPay Ruby SDK'
s.description = 'AmazonPay Ruby SDK'
Expand Down
90 changes: 89 additions & 1 deletion lib/amazon_pay/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ def api_call(url_fragment, method, payload: '', headers: {}, query_params: {})

# Increment the retry counter
retries += 1
print "Retrying\n"
# Raise an exception to force a retry
raise "Transient error: #{response.code}" # Force retry
end
Expand Down Expand Up @@ -266,4 +265,93 @@ def get_refund(refund_id, headers: {})
api_call("#{Constants::REFUNDS_URL}/#{refund_id}", Constants::GET, headers: headers)
end

# API to retrieve a list of reports
# Retrieves a list of reports based on the provided query parameters.
# @see https://developer.amazon.com/docs/amazon-pay-api-v2/reports.html#get-reports
# @param {Object} headers - Optional headers for the request, such as authorization tokens or custom headers.
# @param {Object} query_params - Query parameters to filter the reports, such as report type or processing status.
# @return [HTTPResponse] The response from the API call, which includes a list of reports matching the criteria.
def get_reports(headers: {}, query_params: {})
api_call(Constants::REPORTS, Constants::GET, headers: headers, query_params: query_params)
end

# API to retrieve a specific report by ID
# Retrieves details of a specific report using its unique report ID.
# @see https://developer.amazon.com/docs/amazon-pay-api-v2/reports.html#get-report-by-id
# @param {String} report_id - The unique ID of the report to retrieve.
# @param {Object} headers - Optional headers for the request, such as authorization tokens or custom headers.
# @return [HTTPResponse] The response from the API call, which includes details of the requested report.
def get_report_by_id(report_id, headers: {})
api_call("#{Constants::REPORTS}/#{report_id}", Constants::GET, headers: headers)
end

# API to create a new report
# Creates a new report based on the provided payload.
# @see https://developer.amazon.com/docs/amazon-pay-api-v2/reports.html#create-report
# @param {Object} payload - The payload containing data required to generate the report.
# @param {Object} headers - Optional headers for the request, such as authorization tokens or custom headers.
# @return [HTTPResponse] The response from the API call, which includes confirmation and details of the created report.
def create_report(payload, headers: {})
api_call(Constants::REPORTS, Constants::POST, payload: payload, headers: headers)
end

# API to retrieve a specific report document by ID
# Retrieves the content of a specific report document using its unique report document ID.
# @see https://developer.amazon.com/docs/amazon-pay-api-v2/reports.html#get-report-document
# @param {String} report_document_id - The unique ID of the report document to retrieve.
# @param {Object} headers - Optional headers for the request, such as authorization tokens or custom headers.
# @return [HTTPResponse] The response from the API call, which includes the content of the requested report document.
def get_report_document(report_document_id, headers: {})
api_call("#{Constants::REPORT_DOCUMENTS}/#{report_document_id}", Constants::GET, headers: headers)
end

# API to retrieve a list of report schedules
# Retrieves a list of report schedules based on the provided query parameters.
# @see https://developer.amazon.com/docs/amazon-pay-api-v2/reports.html#get-report-schedules
# @param {Object} headers - Optional headers for the request, such as authorization tokens or custom headers.
# @param {Object} query_params - Query parameters to filter the report schedules, such as schedule type or status.
# @return [HTTPResponse] The response from the API call, which includes a list of report schedules matching the criteria.
def get_report_schedules(headers: {}, query_params: {})
api_call(Constants::REPORT_SCHEDULES, Constants::GET, headers: headers, query_params: query_params)
end

# API to retrieve a specific report schedule by ID
# Retrieves details of a specific report schedule using its unique report schedule ID.
# @see https://developer.amazon.com/docs/amazon-pay-api-v2/reports.html#get-report-schedule-by-id
# @param {String} report_schedule_id - The unique ID of the report schedule to retrieve.
# @param {Object} headers - Optional headers for the request, such as authorization tokens or custom headers.
# @return [HTTPResponse] The response from the API call, which includes details of the requested report schedule.
def get_report_schedule_by_id(report_schedule_id, headers: {})
api_call("#{Constants::REPORT_SCHEDULES}/#{report_schedule_id}", Constants::GET, headers: headers)
end

# API to create a new report schedule
# Creates a new report schedule based on the provided payload.
# @see https://developer.amazon.com/docs/amazon-pay-api-v2/reports.html#create-report-schedule
# @param {Object} payload - The payload containing data required to set up the report schedule.
# @param {Object} headers - Optional headers for the request, such as authorization tokens or custom headers.
# @return [HTTPResponse] The response from the API call, which includes confirmation and details of the created report schedule.
def create_report_schedule(payload, headers: {}, query_params: {})
api_call(Constants::REPORT_SCHEDULES, Constants::POST, payload: payload, headers: headers, query_params: query_params)
end

# API to cancel an existing report schedule by ID
# Cancels a specific report schedule using its unique report schedule ID.
# @see https://developer.amazon.com/docs/amazon-pay-api-v2/reports.html#cancel-report-schedule
# @param {String} report_schedule_id - The unique ID of the report schedule to cancel.
# @param {Object} headers - Optional headers for the request, such as authorization tokens or custom headers.
# @return [HTTPResponse] The response from the API call, which includes confirmation of the cancellation.
def cancel_report_schedule(report_schedule_id, headers: {})
api_call("#{Constants::REPORT_SCHEDULES}/#{report_schedule_id}", Constants::DELETE, headers: headers)
end

# API to retrieve a list of disbursements
# Retrieves a list of disbursements based on the provided query parameters.
# @see https://developer.amazon.com/docs/amazon-pay-api-v2/reports.html#get-disbursements
# @param {Object} headers - Optional headers for the request, such as authorization tokens or custom headers.
# @param {Object} query_params - Query parameters to filter the disbursements, such as date range or status.
# @return [HTTPResponse] The response from the API call, which includes a list of disbursements matching the criteria.
def get_disbursements(headers: {}, query_params: {})
api_call(Constants::DISBURSEMENTS, Constants::GET, headers: headers, query_params: query_params)
end
end
6 changes: 5 additions & 1 deletion lib/amazon_pay/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Constants
SDK_TYPE = "amazon-pay-api-sdk-ruby".freeze
SDK_VERSION = "1.1.0".freeze
SDK_VERSION = "1.2.0".freeze
API_VERSION = "v2".freeze
API_ENDPOINTS = {
'na' => 'pay-api.amazon.com',
Expand Down Expand Up @@ -46,4 +46,8 @@ module Constants
CHARGE_PERMISSIONS_URL = 'chargePermissions'.freeze
CHARGES_URL = 'charges'.freeze
REFUNDS_URL = 'refunds'.freeze
REPORTS = 'reports'.freeze
REPORT_SCHEDULES = 'report-schedules'.freeze
REPORT_DOCUMENTS = 'report-documents'.freeze
DISBURSEMENTS = 'disbursements'.freeze
end
Loading

0 comments on commit 40e0018

Please sign in to comment.