Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ design.txt

.bundle
.ruby-version

.DS_Store
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ The Library supports all APIs under the following services:
* marketpay
* postfmapi
* data_protection
* dispute
* bin_lookup

## Requirements

Expand Down Expand Up @@ -151,6 +153,16 @@ adyen.checkout.version = 50
**data_protection:**
- request_subject_erasure

**dispute:**
- retrieve_applicable_defense_reasons
- supply_defense_document
- delete_dispute_defense_document
- defend_dispute

**bin_lookup:**
- get_3ds_availability
- get_cost_estimate

## Support
If you have a feature request, or spotted a bug or a technical problem, create a GitHub issue. For other questions, contact our [support team](https://support.adyen.com/hc/en-us/requests/new?ticket_form_id=360000705420).

Expand Down
2 changes: 2 additions & 0 deletions lib/adyen-ruby-api-library.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@
require_relative "adyen/services/postfmapi"
require_relative "adyen/services/service"
require_relative "adyen/services/data_protection"
require_relative "adyen/services/dispute"
require_relative "adyen/services/bin_lookup"
require_relative "adyen/hash_with_accessors"
require_relative "adyen/utils/hmac_validator"
23 changes: 15 additions & 8 deletions lib/adyen/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ def service_url_base(service)
when "Account", "Fund", "Notification", "Hop"
url = "https://cal-#{@env}.adyen.com/cal/services"
supports_live_url_prefix = false
when "Recurring", "Payment", "Payout"
when "Recurring", "Payment", "Payout", "BinLookup"
url = "https://pal-#{@env}.adyen.com/pal/servlet"
supports_live_url_prefix = true
when "Terminal"
url = "https://postfmapi-#{@env}.adyen.com/postfmapi/terminal"
supports_live_url_prefix = false
when "DataProtectionService"
when "DataProtectionService", "DisputeService"
url = "https://ca-#{@env}.adyen.com/ca/services"
supports_live_url_prefix = false
else
Expand All @@ -80,7 +80,7 @@ def service_url(service, action, version)
end

# send request to adyen API
def call_adyen_api(service, action, request_data, headers, version)
def call_adyen_api(service, action, request_data, headers, version, with_application_info = false)
# get URL for requested endpoint
url = service_url(service, action, version)

Expand Down Expand Up @@ -125,7 +125,7 @@ def call_adyen_api(service, action, request_data, headers, version)
end

# add application only on checkout service
if service == 'Checkout' || service == 'CheckoutUtility'
if with_application_info
add_application_info(request_data)
end

Expand Down Expand Up @@ -157,16 +157,15 @@ def call_adyen_api(service, action, request_data, headers, version)
# add application_info for analytics
def add_application_info(request_data)
adyenLibrary = {
:name => Adyen::NAME,
:version => Adyen::VERSION.to_s
:name => Adyen::NAME,
:version => Adyen::VERSION.to_s,
}

if request_data[:applicationInfo].nil?
request_data[:applicationInfo] = {};
request_data[:applicationInfo] = {}
end

request_data[:applicationInfo][:adyenLibrary] = adyenLibrary
request_data[:applicationInfo][:adyenLibraryTest] = adyenLibrary
end

# services
Expand Down Expand Up @@ -201,5 +200,13 @@ def postfmapi
def data_protection
@data_protection ||= Adyen::DataProtection.new(self)
end

def dispute
@dispute ||= Adyen::Dispute.new(self)
end

def bin_lookup
@bin_lookup ||= Adyen::BinLookup.new(self)
end
end
end
18 changes: 18 additions & 0 deletions lib/adyen/services/bin_lookup.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require_relative 'service'

module Adyen
class BinLookup < Service
attr_accessor :version
DEFAULT_VERSION = 50

def initialize(client, version = DEFAULT_VERSION)
service = 'BinLookup'
method_names = [
:get_3ds_availability,
:get_cost_estimate
]

super(client, version, service, method_names)
end
end
end
18 changes: 11 additions & 7 deletions lib/adyen/services/checkout.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
require_relative 'service'
require_relative "service"

module Adyen
class Checkout < Service
DEFAULT_VERSION = 50

def initialize(client, version = DEFAULT_VERSION)
service = 'Checkout'
service = "Checkout"
method_names = [
:payment_methods,
:payment_session,
:payment_links
:payment_links,
]
with_application_info = [
:payment_session,
:payment_links,
]

super(client, version, service, method_names)
super(client, version, service, method_names, with_application_info)
end

# This method can't be dynamically defined because
Expand All @@ -25,16 +29,16 @@ def payments(*args)
when 0
Adyen::CheckoutDetail.new(@client, @version)
else
action = 'payments'
action = "payments"
args[1] ||= {} # optional headers arg
@client.call_adyen_api(@service, action, args[0], args[1], @version)
@client.call_adyen_api(@service, action, args[0], args[1], @version, true)
end
end
end

class CheckoutDetail < Service
def initialize(client, version = DEFAULT_VERSION)
@service = 'Checkout'
@service = "Checkout"
@client = client
@version = version
end
Expand Down
20 changes: 20 additions & 0 deletions lib/adyen/services/dispute.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require_relative 'service'

module Adyen
class Dispute < Service
attr_accessor :version
DEFAULT_VERSION = 30

def initialize(client, version = DEFAULT_VERSION)
service = 'DisputeService'
method_names = [
:retrieve_applicable_defense_reasons,
:supply_defense_document,
:delete_dispute_defense_document,
:defend_dispute,
]

super(client, version, service, method_names)
end
end
end
13 changes: 9 additions & 4 deletions lib/adyen/services/payments.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
require_relative 'service'
require_relative "service"

module Adyen
class Payments < Service
attr_accessor :version
DEFAULT_VERSION = 50

def initialize(client, version = DEFAULT_VERSION)
service = 'Payment'
service = "Payment"
method_names = [
:authorise,
:authorise3d,
Expand All @@ -16,10 +16,15 @@ def initialize(client, version = DEFAULT_VERSION)
:refund,
:cancel_or_refund,
:adjust_authorisation,
:donate
:donate,
]
with_application_info = [
:authorise,
:authorise3d,
:authorise3ds2,
]

super(client, version, service, method_names)
super(client, version, service, method_names, with_application_info)
end
end
end
4 changes: 2 additions & 2 deletions lib/adyen/services/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def self.action_for_method_name(method_name)
method_name.to_s.gsub(/_./) { |x| x[1].upcase }
end

def initialize(client, version, service, method_names)
def initialize(client, version, service, method_names, with_application_info = [])
@client = client
@version = version
@service = service
Expand All @@ -20,7 +20,7 @@ def initialize(client, version, service, method_names)
method_names.each do |method_name|
define_singleton_method method_name do |request, headers = {}|
action = self.class.action_for_method_name(method_name)
@client.call_adyen_api(@service, action, request, headers, @version)
@client.call_adyen_api(@service, action, request, headers, @version, with_application_info.include?(method_name))
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/adyen/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Adyen
NAME = "adyen-ruby-api-library"
VERSION = "4.3.0".freeze
VERSION = "4.4.0".freeze
end
15 changes: 15 additions & 0 deletions spec/bin_lookup_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require "spec_helper"

RSpec.describe Adyen::BinLookup, service: "BIN lookup service" do
# client instance to be used in dynamically generated tests
client = create_client(:basic)

# methods / values to test for
# format is defined in spec_helper
test_sets = [
["get_3ds_availability", "threeDS2supported", false],
["get_cost_estimate", "resultCode", "Success"]
]

generate_tests(client, "BinLookup", test_sets, client.bin_lookup)
end
17 changes: 17 additions & 0 deletions spec/dispute_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require "spec_helper"

RSpec.describe Adyen::Dispute, service: "dispute service" do
# client instance to be used in dynamically generated tests
client = create_client(:basic)

# methods / values to test for
# format is defined in spec_helper
test_sets = [
["retrieve_applicable_defense_reasons", "disputeServiceResult", { "success" => true }],
["supply_defense_document", "disputeServiceResult", { "success" => true }],
["delete_dispute_defense_document", "disputeServiceResult", { "success" => true }],
["defend_dispute", "disputeServiceResult", { "success" => true }],
]

generate_tests(client, "DisputeService", test_sets, client.dispute)
end
4 changes: 4 additions & 0 deletions spec/mocks/requests/BinLookup/get_3ds_availability.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"merchantAccount": "TestMerchant",
"cardNumber": "4111111111111111"
}
8 changes: 8 additions & 0 deletions spec/mocks/requests/BinLookup/get_cost_estimate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"amount": {
"currency": "EUR",
"value": 1000
},
"cardNumber": "5101180000000007",
"merchantAccount": "TestMerchant"
}
5 changes: 5 additions & 0 deletions spec/mocks/requests/DisputeService/defend_dispute.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"disputePspReference": "9913486733050065",
"defenseReasonCode": "SupplyDefenseMaterial",
"merchantAccountCode": "YOUR_MERCHANT_ACCOUNT"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"disputePspReference": "9913486733050065",
"merchantAccountCode": "YOUR_MERCHANT_ACCOUNT",
"defenseDocumentType": "MerchandiseDescription"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"merchantAccount": "YOUR_MERCHANT_ACCOUNT",
"disputePspReference": "9913486733050065"
}
11 changes: 11 additions & 0 deletions spec/mocks/requests/DisputeService/supply_defense_document.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"defenseDocuments": [
{
"content": "JVBERi0xLjMKJcTl8uXrp...",
"contentType": "application/pdf",
"defenseDocumentTypeCode": "MerchandiseDescription"
}
],
"disputePspReference": "9913486733050065",
"merchantAccountCode": "YOUR_MERCHANT_ACCOUNT"
}
8 changes: 8 additions & 0 deletions spec/mocks/responses/BinLookup/get_3ds_availability.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"binDetails": {
"issuerCountry": "NL"
},
"threeDS1Supported": true,
"threeDS2CardRangeDetails": [],
"threeDS2supported": false
}
8 changes: 8 additions & 0 deletions spec/mocks/responses/BinLookup/get_cost_estimate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"costEstimateAmount": {
"currency": "EUR",
"value": 1000
},
"resultCode": "Success",
"surchargeType": "PASSTHROUGH"
}
5 changes: 5 additions & 0 deletions spec/mocks/responses/DisputeService/defend_dispute.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"disputeServiceResult": {
"success": true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"disputeServiceResult": {
"success": true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"defenseReasons": [
{
"defenseDocumentTypes": [
{
"available": false,
"defenseDocumentTypeCode": "TIDorInvoice",
"requirementLevel": "Optional"
},
{
"available": false,
"defenseDocumentTypeCode": "DefenseMaterial",
"requirementLevel": "Required"
},
{
"available": false,
"defenseDocumentTypeCode": "AlternativeDefenseMaterial",
"requirementLevel": "AlternativeRequired"
}
],
"defenseReasonCode": "SupplyDefenseMaterial",
"satisfied": false
}
],
"disputeServiceResult": {
"success": true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"disputeServiceResult": {
"success": true
}
}
Loading