Skip to content

Commit 8764097

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents f06582c + 6162730 commit 8764097

File tree

9 files changed

+242
-16
lines changed

9 files changed

+242
-16
lines changed

CHANGELOG.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
### v0.13.0.pre
2+
3+
* features
4+
* Add payment method definitions methods
5+
* `PaymentMethodDefinitions#all`
6+
* `PaymentMethodDefinitions#create`
7+
* `PaymentMethodDefinitions#delete`
8+
* `PaymentMethodDefinitions#find`
9+
* `PaymentMethodDefinitions#update`
10+
* Add possibility to log request `headers` and `bodies`
11+
112
### v0.12.1.pre
213

314
* bug-fixes
@@ -14,7 +25,7 @@
1425
* `Locations#update`
1526

1627
* enhancements
17-
* Use `autoload` instead of `require`
28+
* Use `autoload` instead of `require`
1829

1930
### v0.11.1.pre
2031

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
beyond_api (0.12.1.pre)
4+
beyond_api (0.13.0.pre)
55
faraday (~> 0.15)
66

77
GEM

lib/beyond_api.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
11
require "beyond_api/version"
22

3-
require "beyond_api/connection"
4-
require "beyond_api/request"
5-
require "beyond_api/session"
6-
require "beyond_api/error"
3+
require "logger"
74

85
require "beyond_api/ext"
96
require "beyond_api/utils"
107

11-
require "logger"
12-
138
module BeyondApi
14-
def self.logger
15-
@@logger ||= defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
16-
end
9+
autoload :Connection, "beyond_api/connection"
10+
autoload :Error, "beyond_api/error"
11+
autoload :Logger, "beyond_api/logger"
12+
autoload :Request, "beyond_api/request"
13+
autoload :Session, "beyond_api/session"
1714

18-
def self.logger=(logger)
19-
@@logger = logger
20-
end
15+
extend BeyondApi::Logger
2116

2217
class << self
2318
attr_accessor :configuration
@@ -31,7 +26,8 @@ def self.setup
3126

3227
class Configuration
3328
attr_accessor :client_id, :client_secret, :open_timeout, :timeout, :remove_response_links,
34-
:remove_response_key_underscores, :object_struct_responses, :raise_error_requests
29+
:remove_response_key_underscores, :object_struct_responses, :raise_error_requests,
30+
:log_headers, :log_bodies, :log_level
3531

3632
def initialize
3733
@client_id = nil
@@ -42,6 +38,10 @@ def initialize
4238
@remove_response_key_underscores = false
4339
@object_struct_responses = false
4440
@raise_error_requests = false
41+
42+
@log_level = :info
43+
@log_headers = false
44+
@log_bodies = false
4545
end
4646
end
4747
end

lib/beyond_api/connection.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,15 @@
44

55
module BeyondApi
66
class Connection
7+
LOGGER = ::BeyondApi.logger
8+
LOGGER.level = Kernel.const_get("::Logger::#{BeyondApi.configuration.log_level.to_s.upcase}")
9+
710
def self.default
811
Faraday.new(ssl: { verify: true }) do |faraday|
912
faraday.options[:open_timeout] = BeyondApi.configuration.open_timeout.to_i
1013
faraday.options[:timeout] = BeyondApi.configuration.timeout.to_i
14+
faraday.response :logger, LOGGER, { headers: BeyondApi.configuration.log_headers,
15+
bodies: BeyondApi.configuration.log_bodies }
1116
faraday.headers['Accept'] = 'application/json'
1217
faraday.headers['Content-Type'] = 'application/json'
1318
faraday.request(:multipart)
@@ -20,6 +25,8 @@ def self.token
2025
Faraday.new(ssl: { verify: true }) do |faraday|
2126
faraday.options[:open_timeout] = BeyondApi.configuration.open_timeout.to_i
2227
faraday.options[:timeout] = BeyondApi.configuration.timeout.to_i
28+
faraday.response :logger, LOGGER, { headers: BeyondApi.configuration.log_headers,
29+
bodies: BeyondApi.configuration.log_bodies }
2330
faraday.headers['Accept'] = 'application/json'
2431
faraday.adapter(:net_http)
2532
faraday.basic_auth(BeyondApi.configuration.client_id,

lib/beyond_api/logger.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# frozen_string_literal: true
2+
3+
module BeyondApi
4+
module Logger
5+
def logger
6+
@@logger ||= defined?(Rails) ? ::Rails.logger : ::Logger.new($stdout)
7+
end
8+
9+
def logger=(logger)
10+
@@logger = logger
11+
end
12+
end
13+
end
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
# frozen_string_literal: true
2+
3+
require "beyond_api/utils"
4+
5+
module BeyondApi
6+
class PaymentMethodDefinitions < Base
7+
include BeyondApi::Utils
8+
9+
#
10+
# A +POST+ request is used to create a payment method definition on system level.
11+
#
12+
# $ curl 'https://system.beyondshop.cloud/api/payment-method-definitions' -i -X POST \
13+
# -H 'Content-Type: application/json' \
14+
# -H 'Accept: application/hal+json' \
15+
# -H 'Authorization: Bearer <Access token>' \
16+
# -d '{
17+
# "name": "credit-card",
18+
# "referralUriTemplate": "https://example.com/merchants",
19+
# "statusUriTemplate": "https://example.com/merchants/{shopId}/status",
20+
# "disconnectUriTemplate": "https://example.com/merchants/{shopId}/disconnect",
21+
# "createPaymentUriTemplate": "https://example.com/payments",
22+
# "capturePaymentUriTemplate": "https://example.com/payments/{paymentId}/capture",
23+
# "refundPaymentUriTemplate": "https://example.com/payments/{paymentId}/refund",
24+
# "sandbox": "true",
25+
# "workflow": "PAYMENT_ON_BUY",
26+
# "captureWorkflow": "CAPTURE_ON_ORDER",
27+
# "refund": "NO_REFUND",
28+
# "logos": [{
29+
# "setName" : "official",
30+
# "variant" : "STOREFRONT",
31+
# "uri" : "https://example.com/static/storefront.png"
32+
# }],
33+
# "officialName": {"de-DE" : "Ermögliche deinen Kunden, mit Kreditkarte zu bezahlen.",
34+
# "en-US" : "Allow your customers to pay by credit card."
35+
# },
36+
# "officialDescription": {
37+
# "de-DE" : "Ermögliche deinen Kunden, mit Kreditkarte zu bezahlen.",
38+
# "en-US" : "Allow your customers to pay by credit card."
39+
# },
40+
# "defaultName": {
41+
# "de-DE" : "Kreditkarte",
42+
# "en-US" : "Credit card"
43+
# },
44+
# "defaultDescription": {"de-DE" : "Bezahlen Sie mit Kreditkarte.","en-US" : "Pay by credit card."}}'
45+
#
46+
# @beyond_api.scopes +paym:m+
47+
#
48+
# @param body [Hash] the request body
49+
#
50+
# @return [OpenStruct]
51+
#
52+
# @example
53+
# @payment_method_definitions = session.payment_method_definitions.create(body)
54+
#
55+
def create(body)
56+
response, status = BeyondApi::Request.post(@session, "/payment-method-definitions", body)
57+
58+
handle_response(response, status)
59+
end
60+
61+
#
62+
# A +GET+ request is used to list all payment method definitions on system level.
63+
#
64+
# $ curl 'https://api-shop.beyondshop.cloud/api/payment-method-definitions' -i -X GET \
65+
# -H 'Accept: application/hal+json' \
66+
# -H 'Authorization: Bearer <Access token>'
67+
#
68+
# @beyond_api.scopes +paym:m+
69+
#
70+
# @option params [Boolean] :paginated
71+
# @option params [Integer] :size the page size
72+
# @option params [Integer] :page the page number
73+
#
74+
# @return [OpenStruct]
75+
#
76+
# @example
77+
# @payment_method_definitions = session.payment_method_definitions.all(size: 100, page: 0)
78+
#
79+
def all(params = {})
80+
handle_all_request("/payment-method-definitions", :payment_method_definitions, params)
81+
end
82+
83+
#
84+
# A +GET+ request is used to deactivate a payment method.
85+
#
86+
# $ curl 'https://api-shop.beyondshop.cloud/api/payment-method-definitions/credit-card' -i -X GET \
87+
# -H 'Accept: application/hal+json' \
88+
# -H 'Authorization: Bearer <Access token>'
89+
#
90+
# @beyond_api.scopes +pymt:u+
91+
#
92+
# @param payment_method_definition_id [String] the payment method definition UUID
93+
#
94+
# @return [OpenStruct]
95+
#
96+
# @example
97+
# @payment_method_definition = session.payment_methods.find("credit-card")
98+
#
99+
def find(payment_method_definition_id)
100+
response, status = BeyondApi::Request.get(@session, "/payment-method-definitions/#{payment_method_definition_id}")
101+
102+
handle_response(response, status)
103+
end
104+
105+
#
106+
# A +PUT+ request is used to update a payment method definition on system level.
107+
#
108+
# $ curl 'https://system.beyondshop.cloud/api/payment-method-definitions/credit-card' -i -X PUT \
109+
# -H 'Content-Type: application/json' \
110+
# -H 'Accept: application/hal+json' \
111+
# -H 'Authorization: Bearer <Access token>' \
112+
# -d '{
113+
# "name": "credit-card-updated",
114+
# "referralUriTemplate": "https://example.com/merchants",
115+
# "statusUriTemplate": "https://example.com/merchants/{shopId}/status",
116+
# "disconnectUriTemplate": "https://example.com/merchants/{shopId}/disconnect",
117+
# "createPaymentUriTemplate": "https://example.com/payments",
118+
# "capturePaymentUriTemplate": "https://example.com/payments/{paymentId}/capture",
119+
# "refundPaymentUriTemplate": "https://example.com/payments/{paymentId}/refund",
120+
# "workflow": "PAYMENT_ON_SELECTION",
121+
# "captureWorkflow": "CAPTURE_ON_DEMAND",
122+
# "refund": "NO_REFUND",
123+
# "logos": [{
124+
# "setName" : "official",
125+
# "variant" : "STOREFRONT",
126+
# "uri" : "https://example.com/static/storefront.png"
127+
# }],
128+
# "officialName": {"de-DE" : "Ermögliche deinen Kunden, mit Kreditkarte zu bezahlen.",
129+
# "en-US" : "Allow your customers to pay by credit card."
130+
# },
131+
# "officialDescription": {
132+
# "de-DE" : "Ermögliche deinen Kunden, mit Kreditkarte zu bezahlen.",
133+
# "en-US" : "Allow your customers to pay by credit card."
134+
# },
135+
# "defaultName": {
136+
# "de-DE" : "Kreditkarte",
137+
# "en-US" : "Credit card"
138+
# },
139+
# "defaultDescription": {"de-DE" : "Bezahlen Sie mit Kreditkarte.","en-US" : "Pay by credit card."}}'
140+
#
141+
# @beyond_api.scopes +paym:m+
142+
#
143+
# @param payment_method_definition_id [String] the payment method definition UUID
144+
# @param body [Hash] the request body
145+
#
146+
# @return [OpenStruct]
147+
#
148+
# @example
149+
# @payment_method_definition = session.payment_method_definitions.update("credit_card", body)
150+
#
151+
def update(payment_method_definition_id, body)
152+
response, status = BeyondApi::Request.put(@session, "/payment-method-definitions/#{payment_method_definition_id}")
153+
154+
handle_response(response, status)
155+
end
156+
157+
#
158+
# A +DELETE+ request is used to delete a payment method definition on system level.
159+
#
160+
# $ curl 'https://system.beyondshop.cloud/api/payment-method-definitions/credit-card' -i -X DELETE \
161+
# -H 'Accept: application/hal+json' \
162+
# -H 'Authorization: Bearer <Access token>'
163+
#
164+
# @return true
165+
#
166+
# @example
167+
# session.payment_method_definitions.delete("credit-card")
168+
#
169+
def delete(payment_method_definition_id)
170+
response, status = BeyondApi::Request.delete(@session, "/payment-method-definitions/#{payment_method_definition_id}", body)
171+
172+
handle_response(response, status, respond_with_true: true)
173+
end
174+
end
175+
end

lib/beyond_api/session.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module BeyondApi
1010
autoload :NewsletterTarget, "beyond_api/resources/newsletter_target"
1111
autoload :OrderSettings, "beyond_api/resources/order_settings"
1212
autoload :Orders, "beyond_api/resources/orders"
13+
autoload :PaymentMethodDefinitions, "beyond_api/resources/payment_method_definitions"
1314
autoload :PaymentMethods, "beyond_api/resources/payment_methods"
1415
autoload :ProductAttributeDefinitions, "beyond_api/resources/product_attribute_definitions"
1516
autoload :ProductsView, "beyond_api/resources/products_view"
@@ -65,6 +66,10 @@ def orders
6566
BeyondApi::Orders.new(self)
6667
end
6768

69+
def payment_method_definitions
70+
BeyondApi::PaymentMethodDefinitions.new(self)
71+
end
72+
6873
def payment_methods
6974
BeyondApi::PaymentMethods.new(self)
7075
end

lib/beyond_api/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module BeyondApi
2-
VERSION = "0.12.1.pre".freeze
2+
VERSION = "0.13.0.pre".freeze
33
end

lib/generators/templates/beyond_api_initializer.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,21 @@
1212
# Configure the request timeout in seconds. Default is 5 seconds.
1313
# config.timeout = 5.seconds
1414

15+
# ==> Log configuration
16+
17+
# Configure the log level. Must be one of :debug, :info, :warn, :error,
18+
# :fatal or :unknown. Default is :info.
19+
#
20+
# config.log_level = :info
21+
22+
# Configure is response headers should be logged. Default is false.
23+
#
24+
# config.log_headers = false
25+
26+
# Configure is response bodies should be logged. Default is false.
27+
#
28+
# config.log_bodies = false
29+
1530
# ==> Response configuration
1631
# Configure if :_links should be removed from response. Default is false and
1732
# :_links are gonna be part of the response.

0 commit comments

Comments
 (0)