Class: AmazonPayClient
- Inherits:
-
Object
- Object
- AmazonPayClient
- Includes:
- PaymentServiceProviderClient
- Defined in:
- lib/amazon-pay-api-sdk-ruby/client.rb
Overview
AmazonPayClient class provides methods to interact with Amazon Pay API
Instance Method Summary collapse
-
#api_call(url_fragment, method, payload: '', headers: {}, query_params: {}) ⇒ HTTPResponse
Perform an API call to Amazon Pay.
-
#cancel_charge(charge_id, payload, headers: {}) ⇒ HTTPResponse
API to cancel a charge Cancels an existing charge, preventing it from being captured.
-
#cancel_report_schedule(report_schedule_id, headers: {}) ⇒ HTTPResponse
API to cancel an existing report schedule by ID Cancels a specific report schedule using its unique report schedule ID.
-
#capture_charge(charge_id, payload, headers: {}) ⇒ HTTPResponse
API to capture a charge Captures an authorized charge to collect the funds.
-
#close_charge_permission(charge_permission_id, payload, headers: {}) ⇒ HTTPResponse
API to close a Charge Permission object Closes a Charge Permission, preventing further charges.
-
#complete_checkout_session(checkout_session_id, payload, headers: {}) ⇒ HTTPResponse
API to complete a Checkout Session Confirms the completion of buyer checkout.
-
#create_charge(payload, headers: {}) ⇒ HTTPResponse
API to create a new charge Initiates a new charge with the provided payment details.
-
#create_checkout_session(payload, headers: {}) ⇒ HTTPResponse
API to create a CheckoutSession object Creates a new CheckoutSession object.
-
#create_merchant_account(payload, headers: {}) ⇒ HTTPResponse
Creates a merchant account.
-
#create_refund(payload, headers: {}) ⇒ HTTPResponse
API to create a refund Initiates a new refund for a previously captured charge.
-
#create_report(payload, headers: {}) ⇒ HTTPResponse
API to create a new report Creates a new report based on the provided payload.
-
#create_report_schedule(payload, headers: {}, query_params: {}) ⇒ HTTPResponse
API to create a new report schedule Creates a new report schedule based on the provided payload.
-
#finalize_checkout_session(checkout_session_id, payload, headers: {}) ⇒ HTTPResponse
API to finalize a Checkout Session Finalizes the checkout process by confirming the payment and completing the session.
-
#generate_button_signature(payload) ⇒ String
Generates a signature for the given payload This method is used to generate a signature for an Amazon Pay button payload.
-
#get_buyer(buyer_token, headers: {}) ⇒ HTTPResponse
API to retrieve Buyer information Fetches details of a Buyer using the buyer token provided.
-
#get_charge(charge_id, headers: {}) ⇒ HTTPResponse
API to retrieve charge details Retrieves details of an existing charge using its unique charge ID.
-
#get_charge_permission(charge_permission_id, headers: {}) ⇒ HTTPResponse
API to retrieve a Charge Permission object Fetches details of a Charge Permission, which is associated with a Checkout Session.
-
#get_checkout_session(checkout_session_id, headers: {}) ⇒ HTTPResponse
API to get a CheckoutSession object Retrieves details of a previously created CheckoutSession object.
-
#get_disbursements(headers: {}, query_params: {}) ⇒ HTTPResponse
API to retrieve a list of disbursements Retrieves a list of disbursements based on the provided query parameters.
-
#get_refund(refund_id, headers: {}) ⇒ HTTPResponse
API to retrieve refund details Retrieves details of an existing refund using its unique refund ID.
-
#get_report_by_id(report_id, headers: {}) ⇒ HTTPResponse
API to retrieve a specific report by ID Retrieves details of a specific report using its unique report ID.
-
#get_report_document(report_document_id, headers: {}) ⇒ HTTPResponse
API to retrieve a specific report document by ID Retrieves the content of a specific report document using its unique report document ID.
-
#get_report_schedule_by_id(report_schedule_id, headers: {}) ⇒ HTTPResponse
API to retrieve a specific report schedule by ID Retrieves details of a specific report schedule using its unique report schedule ID.
-
#get_report_schedules(headers: {}, query_params: {}) ⇒ HTTPResponse
API to retrieve a list of report schedules Retrieves a list of report schedules based on the provided query parameters.
-
#get_reports(headers: {}, query_params: {}) ⇒ HTTPResponse
API to retrieve a list of reports Retrieves a list of reports based on the provided query parameters.
-
#initialize(config) ⇒ AmazonPayClient
constructor
Initialize the client with configuration settings.
-
#merchant_account_claim(merchant_account_id, payload, headers: {}) ⇒ HTTPResponse
Claims a merchant account.
-
#update_charge(charge_id, payload, headers: {}) ⇒ HTTPResponse
API to retrieve charge details.
-
#update_charge_permission(charge_permission_id, payload, headers: {}) ⇒ HTTPResponse
API to update a Charge Permission object Updates a previously created Charge Permission with new information.
-
#update_checkout_session(checkout_session_id, payload, headers: {}) ⇒ HTTPResponse
API to update a CheckoutSession object Updates a previously created CheckoutSession object with new information.
-
#update_merchant_account(merchant_account_id, payload, headers: {}) ⇒ HTTPResponse
Updates a merchant account.
Methods included from PaymentServiceProviderClient
#contest_dispute, #create_dispute, #get_dispute, #update_dispute, #upload_file
Constructor Details
#initialize(config) ⇒ AmazonPayClient
Initialize the client with configuration settings
10 11 12 |
# File 'lib/amazon-pay-api-sdk-ruby/client.rb', line 10 def initialize(config) @helper = ClientHelper.new(config) end |
Instance Method Details
#api_call(url_fragment, method, payload: '', headers: {}, query_params: {}) ⇒ HTTPResponse
Perform an API call to Amazon Pay
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/amazon-pay-api-sdk-ruby/client.rb', line 21 def api_call(url_fragment, method, payload: '', headers: {}, query_params: {}) # Convert query parameters into a URL-encoded query string query = @helper.to_query(query_params) # Build the full URI by combining the URL fragment and query string uri = @helper.build_uri(url_fragment, query) # Initialize the retry counter retries = 0 begin # Create a new HTTP request with the specified method, URI, and payload request = @helper.create_request(method, uri, payload) # Generate signed headers for the request signed_headers = @helper.signed_headers(method, uri, request.body, headers, query) # Set the signed headers on the request @helper.set_request_headers(request, signed_headers) # Send the HTTP request and get the response response = @helper.send_request(uri, request) # Check if the response code indicates a retryable error and if we haven't exceeded the maximum retries if Constants::RETRYABLE_ERROR_CODES.include?(response.code.to_i) && retries < Constants::MAX_RETRIES # Wait for a specified backoff period before retrying sleep Constants::BACKOFF_TIMES[retries] # Increment the retry counter retries += 1 # Raise an exception to force a retry raise "Transient error: #{response.code}" # Force retry end # Return the response if no retry is needed response rescue => e # Catches any exceptions that occur during the request if retries < Constants::MAX_RETRIES # Increment the retry counter retries += 1 # Wait for a specified backoff period before retrying sleep Constants::BACKOFF_TIMES[retries - 1] # Backoff before retry # Retry the request retry else # After maximum retries are exhausted, return the response from the last attempt response end end end |
#cancel_charge(charge_id, payload, headers: {}) ⇒ HTTPResponse
API to cancel a charge Cancels an existing charge, preventing it from being captured.
257 258 259 |
# File 'lib/amazon-pay-api-sdk-ruby/client.rb', line 257 def cancel_charge(charge_id, payload, headers: {}) api_call("#{Constants::CHARGES_URL}/#{charge_id}/cancel", Constants::DELETE, payload: payload, headers: headers) end |
#cancel_report_schedule(report_schedule_id, headers: {}) ⇒ HTTPResponse
API to cancel an existing report schedule by ID Cancels a specific report schedule using its unique report schedule ID.
357 358 359 |
# File 'lib/amazon-pay-api-sdk-ruby/client.rb', line 357 def cancel_report_schedule(report_schedule_id, headers: {}) api_call("#{Constants::REPORT_SCHEDULES}/#{report_schedule_id}", Constants::DELETE, headers: headers) end |
#capture_charge(charge_id, payload, headers: {}) ⇒ HTTPResponse
API to capture a charge Captures an authorized charge to collect the funds.
246 247 248 |
# File 'lib/amazon-pay-api-sdk-ruby/client.rb', line 246 def capture_charge(charge_id, payload, headers: {}) api_call("#{Constants::CHARGES_URL}/#{charge_id}/capture", Constants::POST, payload: payload, headers: headers) end |
#close_charge_permission(charge_permission_id, payload, headers: {}) ⇒ HTTPResponse
API to close a Charge Permission object Closes a Charge Permission, preventing further charges.
203 204 205 |
# File 'lib/amazon-pay-api-sdk-ruby/client.rb', line 203 def (, payload, headers: {}) api_call("#{Constants::CHARGE_PERMISSIONS_URL}/#{}/close", Constants::DELETE, payload: payload, headers: headers) end |
#complete_checkout_session(checkout_session_id, payload, headers: {}) ⇒ HTTPResponse
API to complete a Checkout Session Confirms the completion of buyer checkout.
160 161 162 |
# File 'lib/amazon-pay-api-sdk-ruby/client.rb', line 160 def complete_checkout_session(checkout_session_id, payload, headers: {}) api_call("#{Constants::CHECKOUT_SESSION_URL}/#{checkout_session_id}/complete", Constants::POST, payload: payload, headers: headers) end |
#create_charge(payload, headers: {}) ⇒ HTTPResponse
API to create a new charge Initiates a new charge with the provided payment details.
213 214 215 |
# File 'lib/amazon-pay-api-sdk-ruby/client.rb', line 213 def create_charge(payload, headers: {}) api_call(Constants::CHARGES_URL, Constants::POST, payload: payload, headers: headers) end |
#create_checkout_session(payload, headers: {}) ⇒ HTTPResponse
API to create a CheckoutSession object Creates a new CheckoutSession object.
128 129 130 |
# File 'lib/amazon-pay-api-sdk-ruby/client.rb', line 128 def create_checkout_session(payload, headers: {}) api_call(Constants::CHECKOUT_SESSION_URL, Constants::POST, payload: payload, headers: headers) end |
#create_merchant_account(payload, headers: {}) ⇒ HTTPResponse
Creates a merchant account
81 82 83 |
# File 'lib/amazon-pay-api-sdk-ruby/client.rb', line 81 def create_merchant_account(payload, headers: {}) api_call(Constants::MERCHANT_ACCOUNTS_BASE_URL, Constants::POST, payload: payload, headers: headers) end |
#create_refund(payload, headers: {}) ⇒ HTTPResponse
API to create a refund Initiates a new refund for a previously captured charge.
267 268 269 |
# File 'lib/amazon-pay-api-sdk-ruby/client.rb', line 267 def create_refund(payload, headers: {}) api_call(Constants::REFUNDS_URL, Constants::POST, payload: payload, headers: headers) end |
#create_report(payload, headers: {}) ⇒ HTTPResponse
API to create a new report Creates a new report based on the provided payload.
307 308 309 |
# File 'lib/amazon-pay-api-sdk-ruby/client.rb', line 307 def create_report(payload, headers: {}) api_call(Constants::REPORTS, Constants::POST, payload: payload, headers: headers) end |
#create_report_schedule(payload, headers: {}, query_params: {}) ⇒ HTTPResponse
API to create a new report schedule Creates a new report schedule based on the provided payload.
347 348 349 |
# File 'lib/amazon-pay-api-sdk-ruby/client.rb', line 347 def create_report_schedule(payload, headers: {}, query_params: {}) api_call(Constants::REPORT_SCHEDULES, Constants::POST, payload: payload, headers: headers, query_params: query_params) end |
#finalize_checkout_session(checkout_session_id, payload, headers: {}) ⇒ HTTPResponse
API to finalize a Checkout Session Finalizes the checkout process by confirming the payment and completing the session.
171 172 173 |
# File 'lib/amazon-pay-api-sdk-ruby/client.rb', line 171 def finalize_checkout_session(checkout_session_id, payload, headers: {}) api_call("#{Constants::CHECKOUT_SESSION_URL}/#{checkout_session_id}/finalize", Constants::POST, payload: payload, headers: headers) end |
#generate_button_signature(payload) ⇒ String
Generates a signature for the given payload This method is used to generate a signature for an Amazon Pay button payload. 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.
108 109 110 |
# File 'lib/amazon-pay-api-sdk-ruby/client.rb', line 108 def (payload) @helper.sign(payload.is_a?(String) ? payload : JSON.generate(payload)) end |
#get_buyer(buyer_token, headers: {}) ⇒ HTTPResponse
API to retrieve Buyer information Fetches details of a Buyer using the buyer token provided.
118 119 120 |
# File 'lib/amazon-pay-api-sdk-ruby/client.rb', line 118 def get_buyer(buyer_token, headers: {}) api_call("#{Constants::BUYERS_URL}/#{buyer_token}", Constants::GET, headers: headers) end |
#get_charge(charge_id, headers: {}) ⇒ HTTPResponse
API to retrieve charge details Retrieves details of an existing charge using its unique charge ID.
223 224 225 |
# File 'lib/amazon-pay-api-sdk-ruby/client.rb', line 223 def get_charge(charge_id, headers: {}) api_call("#{Constants::CHARGES_URL}/#{charge_id}", Constants::GET, headers: headers) end |
#get_charge_permission(charge_permission_id, headers: {}) ⇒ HTTPResponse
API to retrieve a Charge Permission object Fetches details of a Charge Permission, which is associated with a Checkout Session.
181 182 183 |
# File 'lib/amazon-pay-api-sdk-ruby/client.rb', line 181 def (, headers: {}) api_call("#{Constants::CHARGE_PERMISSIONS_URL}/#{}", Constants::GET, headers: headers) end |
#get_checkout_session(checkout_session_id, headers: {}) ⇒ HTTPResponse
API to get a CheckoutSession object Retrieves details of a previously created CheckoutSession object.
138 139 140 |
# File 'lib/amazon-pay-api-sdk-ruby/client.rb', line 138 def get_checkout_session(checkout_session_id, headers: {}) api_call("#{Constants::CHECKOUT_SESSION_URL}/#{checkout_session_id}", Constants::GET, headers: headers) end |
#get_disbursements(headers: {}, query_params: {}) ⇒ HTTPResponse
API to retrieve a list of disbursements Retrieves a list of disbursements based on the provided query parameters.
367 368 369 |
# File 'lib/amazon-pay-api-sdk-ruby/client.rb', line 367 def get_disbursements(headers: {}, query_params: {}) api_call(Constants::DISBURSEMENTS, Constants::GET, headers: headers, query_params: query_params) end |
#get_refund(refund_id, headers: {}) ⇒ HTTPResponse
API to retrieve refund details Retrieves details of an existing refund using its unique refund ID.
277 278 279 |
# File 'lib/amazon-pay-api-sdk-ruby/client.rb', line 277 def get_refund(refund_id, headers: {}) api_call("#{Constants::REFUNDS_URL}/#{refund_id}", Constants::GET, headers: headers) end |
#get_report_by_id(report_id, headers: {}) ⇒ HTTPResponse
API to retrieve a specific report by ID Retrieves details of a specific report using its unique report ID.
297 298 299 |
# File 'lib/amazon-pay-api-sdk-ruby/client.rb', line 297 def get_report_by_id(report_id, headers: {}) api_call("#{Constants::REPORTS}/#{report_id}", Constants::GET, headers: headers) end |
#get_report_document(report_document_id, headers: {}) ⇒ HTTPResponse
API to retrieve a specific report document by ID Retrieves the content of a specific report document using its unique report document ID.
317 318 319 |
# File 'lib/amazon-pay-api-sdk-ruby/client.rb', line 317 def get_report_document(report_document_id, headers: {}) api_call("#{Constants::REPORT_DOCUMENTS}/#{report_document_id}", Constants::GET, headers: headers) end |
#get_report_schedule_by_id(report_schedule_id, headers: {}) ⇒ HTTPResponse
API to retrieve a specific report schedule by ID Retrieves details of a specific report schedule using its unique report schedule ID.
337 338 339 |
# File 'lib/amazon-pay-api-sdk-ruby/client.rb', line 337 def get_report_schedule_by_id(report_schedule_id, headers: {}) api_call("#{Constants::REPORT_SCHEDULES}/#{report_schedule_id}", Constants::GET, headers: headers) end |
#get_report_schedules(headers: {}, query_params: {}) ⇒ HTTPResponse
API to retrieve a list of report schedules Retrieves a list of report schedules based on the provided query parameters.
327 328 329 |
# File 'lib/amazon-pay-api-sdk-ruby/client.rb', line 327 def get_report_schedules(headers: {}, query_params: {}) api_call(Constants::REPORT_SCHEDULES, Constants::GET, headers: headers, query_params: query_params) end |
#get_reports(headers: {}, query_params: {}) ⇒ HTTPResponse
API to retrieve a list of reports Retrieves a list of reports based on the provided query parameters.
287 288 289 |
# File 'lib/amazon-pay-api-sdk-ruby/client.rb', line 287 def get_reports(headers: {}, query_params: {}) api_call(Constants::REPORTS, Constants::GET, headers: headers, query_params: query_params) end |
#merchant_account_claim(merchant_account_id, payload, headers: {}) ⇒ HTTPResponse
Claims a merchant account
99 100 101 |
# File 'lib/amazon-pay-api-sdk-ruby/client.rb', line 99 def merchant_account_claim(merchant_account_id, payload, headers: {}) api_call("#{Constants::MERCHANT_ACCOUNTS_BASE_URL}/#{merchant_account_id}/claim", Constants::POST, payload: payload, headers: headers) end |
#update_charge(charge_id, payload, headers: {}) ⇒ HTTPResponse
API to retrieve charge details. The updateCharge operation is used to update the charge status of any PSP (Payment Service Provider) processed payment method (PPM) transactions. Please note that is API is supported only for PSPs (Payment Service Provider)
235 236 237 |
# File 'lib/amazon-pay-api-sdk-ruby/client.rb', line 235 def update_charge(charge_id, payload, headers: {}) api_call("#{Constants::CHARGES_URL}/#{charge_id}", Constants::PATCH, payload: payload, headers: headers) end |
#update_charge_permission(charge_permission_id, payload, headers: {}) ⇒ HTTPResponse
API to update a Charge Permission object Updates a previously created Charge Permission with new information.
192 193 194 |
# File 'lib/amazon-pay-api-sdk-ruby/client.rb', line 192 def (, payload, headers: {}) api_call("#{Constants::CHARGE_PERMISSIONS_URL}/#{}", Constants::PATCH, payload: payload, headers: headers) end |
#update_checkout_session(checkout_session_id, payload, headers: {}) ⇒ HTTPResponse
API to update a CheckoutSession object Updates a previously created CheckoutSession object with new information.
149 150 151 |
# File 'lib/amazon-pay-api-sdk-ruby/client.rb', line 149 def update_checkout_session(checkout_session_id, payload, headers: {}) api_call("#{Constants::CHECKOUT_SESSION_URL}/#{checkout_session_id}", Constants::PATCH, payload: payload, headers: headers) end |
#update_merchant_account(merchant_account_id, payload, headers: {}) ⇒ HTTPResponse
Updates a merchant account
90 91 92 |
# File 'lib/amazon-pay-api-sdk-ruby/client.rb', line 90 def update_merchant_account(merchant_account_id, payload, headers: {}) api_call("#{Constants::MERCHANT_ACCOUNTS_BASE_URL}/#{merchant_account_id}", Constants::PATCH, payload: payload, headers: headers) end |