amazon-pay-api-sdk-ruby 1.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 428da5a80e49d6cf400205eea58757174f259abce2bb6cc7a83aecd0c1554f5f
4
- data.tar.gz: b809960b865a226d7796e506d1712759c0db90119cd886942b5aa9d6ed125681
3
+ metadata.gz: 439cdb07dc4f4d22baaf1d26710a1163cfedd565a6d56a5d0e61b0afdcc2c981
4
+ data.tar.gz: 358f1dfb78f49d1270dc4a457e5664959a40aae6dec6db51476ec6e57e926853
5
5
  SHA512:
6
- metadata.gz: 70c5fb962cf91183aca482ad024752e41a11e398cc666bc87aae026cfbef0efa813b0e36d3b5352f184638efe633f6811927db2a29607b115e59fb1af05836a4
7
- data.tar.gz: 4f62e310db2e153b5c3110a36498e66a81f0f99d9bed70de7c8722feb1c076392b510233df447f37663e23634a5d567b118806beadc01749947de3817efda2df
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 './lib/amazon_pay'
52
+ require 'amazon-pay-api-sdk-ruby'
51
53
 
52
54
  client = AmazonPayClient.new(config)
53
55
 
@@ -509,6 +511,32 @@ else
509
511
  end
510
512
  ```
511
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
+
512
540
  ### Capture Charge
513
541
 
514
542
  ```ruby
@@ -744,4 +772,125 @@ else
744
772
  puts "Status: #{response.code}"
745
773
  puts response.body
746
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
747
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)
@@ -223,6 +224,18 @@ class AmazonPayClient
223
224
  api_call("#{Constants::CHARGES_URL}/#{charge_id}", Constants::GET, headers: headers)
224
225
  end
225
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
+
226
239
  # API to capture a charge
227
240
  # Captures an authorized charge to collect the funds.
228
241
  # @see https://developer.amazon.com/docs/amazon-pay-api-v2/charge.html#capture-charge
@@ -2,7 +2,7 @@ require 'net/http'
2
2
 
3
3
  module Constants
4
4
  SDK_TYPE = "amazon-pay-api-sdk-ruby".freeze
5
- SDK_VERSION = "1.2.0".freeze
5
+ SDK_VERSION = "2.0.0".freeze
6
6
  API_VERSION = "v2".freeze
7
7
  API_ENDPOINTS = {
8
8
  'na' => 'pay-api.amazon.com',
@@ -50,4 +50,48 @@ module Constants
50
50
  REPORT_SCHEDULES = 'report-schedules'.freeze
51
51
  REPORT_DOCUMENTS = 'report-documents'.freeze
52
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
53
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
@@ -0,0 +1,3 @@
1
+ require_relative './amazon-pay-api-sdk-ruby/client'
2
+ require_relative './amazon-pay-api-sdk-ruby/client_helper'
3
+ require_relative "./amazon-pay-api-sdk-ruby/constants"
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.2.0
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: 2024-09-06 00:00:00.000000000 Z
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: :runtime
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/amazon_pay.rb
50
- - lib/amazon_pay/client.rb
51
- - lib/amazon_pay/client_helper.rb
52
- - lib/amazon_pay/constants.rb
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.rb DELETED
@@ -1,3 +0,0 @@
1
- require_relative './amazon_pay/client'
2
- require_relative './amazon_pay/client_helper'
3
- require_relative "./amazon_pay/constants"