braintree 4.24.0 → 4.25.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/braintree/customer_session_gateway.rb +194 -0
- data/lib/braintree/error_result.rb +1 -1
- data/lib/braintree/errors.rb +2 -1
- data/lib/braintree/gateway.rb +4 -0
- data/lib/braintree/graphql/enums/recommendations.rb +7 -0
- data/lib/braintree/graphql/enums/recommended_payment_option.rb +8 -0
- data/lib/braintree/graphql/inputs/create_customer_session_input.rb +35 -0
- data/lib/braintree/graphql/inputs/customer_recommendations_input.rb +41 -0
- data/lib/braintree/graphql/inputs/customer_session_input.rb +39 -0
- data/lib/braintree/graphql/inputs/phone_input.rb +32 -0
- data/lib/braintree/graphql/inputs/update_customer_session_input.rb +37 -0
- data/lib/braintree/graphql/types/customer_recommendations_payload.rb +32 -0
- data/lib/braintree/graphql/types/payment_options.rb +33 -0
- data/lib/braintree/graphql/unions/customer_recommendations.rb +34 -0
- data/lib/braintree/graphql_client.rb +16 -0
- data/lib/braintree/successful_result.rb +2 -0
- data/lib/braintree/version.rb +1 -1
- data/lib/braintree.rb +11 -0
- data/spec/integration/braintree/customer_session_spec.rb +143 -0
- data/spec/unit/braintree/customer_session_gateway_spec.rb +120 -0
- data/spec/unit/braintree/graphql/create_customer_session_input_spec.rb +81 -0
- data/spec/unit/braintree/graphql/customer_recommendations_input_spec.rb +110 -0
- data/spec/unit/braintree/graphql/customer_session_input_spec.rb +81 -0
- data/spec/unit/braintree/graphql/phone_input_spec.rb +51 -0
- data/spec/unit/braintree/graphql/update_customer_session_input_spec.rb +93 -0
- data/spec/unit/braintree/graphql_client_spec.rb +37 -0
- metadata +21 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a53b0f33066dc60083b87ba8eb176eecef8e765c87d4b0073f09d74ce584aeaf
|
4
|
+
data.tar.gz: '09b4b509edaa9c5a8d20a52ee735eca5067a28c05fd01401a1a08034b84d6d49'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae0bc77b138805d06321f200d61376328173630dc730f0fecd91483b70fd35f7817632323923a8bcf95c76c99b095825f472101f2bc3a657ad7d6c8d278ec5a2
|
7
|
+
data.tar.gz: 8d28568a72404894d70b00546f2dd391520253cbe1729d852bbea67ebfbf8d65857389a42783b8f9923dee8add8677e38879421c5a9262f5d7a50076f04e2887
|
@@ -0,0 +1,194 @@
|
|
1
|
+
# Creates and manages PayPal customer sessions.
|
2
|
+
|
3
|
+
module Braintree
|
4
|
+
class CustomerSessionGateway
|
5
|
+
CREATE_CUSTOMER_SESSION = <<~GRAPHQL
|
6
|
+
mutation CreateCustomerSession($input: CreateCustomerSessionInput!) {
|
7
|
+
createCustomerSession(input: $input) {
|
8
|
+
sessionId
|
9
|
+
}
|
10
|
+
}
|
11
|
+
GRAPHQL
|
12
|
+
|
13
|
+
UPDATE_CUSTOMER_SESSION = <<~GRAPHQL
|
14
|
+
mutation UpdateCustomerSession($input: UpdateCustomerSessionInput!) {
|
15
|
+
updateCustomerSession(input: $input) {
|
16
|
+
sessionId
|
17
|
+
}
|
18
|
+
}
|
19
|
+
GRAPHQL
|
20
|
+
|
21
|
+
GET_CUSTOMER_RECOMMENDATIONS = <<~GRAPHQL
|
22
|
+
query CustomerRecommendations($input: CustomerRecommendationsInput!) {
|
23
|
+
customerRecommendations(input: $input) {
|
24
|
+
isInPayPalNetwork
|
25
|
+
recommendations {
|
26
|
+
... on PaymentRecommendations {
|
27
|
+
paymentOptions {
|
28
|
+
paymentOption
|
29
|
+
recommendedPriority
|
30
|
+
}
|
31
|
+
}
|
32
|
+
}
|
33
|
+
}
|
34
|
+
}
|
35
|
+
GRAPHQL
|
36
|
+
|
37
|
+
def initialize(gateway, graphql_client)
|
38
|
+
@gateway = gateway
|
39
|
+
@graphql_client = graphql_client
|
40
|
+
end
|
41
|
+
|
42
|
+
# Creates a new customer session.
|
43
|
+
#
|
44
|
+
# Example:
|
45
|
+
# customer = {
|
46
|
+
# email: "test@example.com",
|
47
|
+
# device_fingerprint_id: "1234",
|
48
|
+
# phone: {country_phone_code: "1", phone_number: "5555555555"},
|
49
|
+
# paypal_app_installed: true,
|
50
|
+
# venmo_app_installed: true,
|
51
|
+
# }
|
52
|
+
# input = Braintree::CreateCustomerSessionInput.new(
|
53
|
+
# customer: customer,
|
54
|
+
# )
|
55
|
+
# result = gateway.customer_session.create_customer_session(input)
|
56
|
+
# if result.success?
|
57
|
+
# puts "Created session #{result.session_id}"
|
58
|
+
# else
|
59
|
+
# puts "Validations failed"
|
60
|
+
# puts result.errors.first.message
|
61
|
+
# end
|
62
|
+
#
|
63
|
+
# @param input [CreateCustomerSessionInput] The input parameters for creating a customer session.
|
64
|
+
#
|
65
|
+
# @return [(Successful|Error)Result] A result object with session ID if successful, or errors otherwise.
|
66
|
+
#
|
67
|
+
# @raise [UnexpectedError] If there is an unexpected error during the process.
|
68
|
+
def create_customer_session(input)
|
69
|
+
execute_mutation(CREATE_CUSTOMER_SESSION, input, :createCustomerSession)
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
# Updates an existing customer session.
|
74
|
+
#
|
75
|
+
# Example:
|
76
|
+
# customer = {
|
77
|
+
# email: "test@example.com",
|
78
|
+
# device_fingerprint_id: "1234",
|
79
|
+
# phone: {country_phone_code: "1", phone_number: "5555555555"},
|
80
|
+
# paypal_app_installed: true,
|
81
|
+
# venmo_app_installed: true,
|
82
|
+
# }
|
83
|
+
# input = Braintree::UpdateCustomerSessionInput.new(
|
84
|
+
# session_id: "11EF-34BC-2702904B-9026-555555555555",
|
85
|
+
# customer: customer,
|
86
|
+
# )
|
87
|
+
# result = gateway.customer_session.updated_customer_session(input)
|
88
|
+
# if result.success?
|
89
|
+
# puts "Updated session #{result.session_id}"
|
90
|
+
# else
|
91
|
+
# puts "Validations failed"
|
92
|
+
# puts result.errors.first.message
|
93
|
+
# end
|
94
|
+
#
|
95
|
+
# @param input [UpdateCustomerSessionInput] The input parameters for updating a customer session.
|
96
|
+
#
|
97
|
+
# @return [(Successful|Error)Result] A result object with session ID if successful, or errors otherwise.
|
98
|
+
#
|
99
|
+
# @raise [UnexpectedError] If there is an unexpected error during the process.
|
100
|
+
def update_customer_session(input)
|
101
|
+
execute_mutation(UPDATE_CUSTOMER_SESSION, input, :updateCustomerSession)
|
102
|
+
end
|
103
|
+
|
104
|
+
# Retrieves customer recommendations associated with a customer session.
|
105
|
+
#
|
106
|
+
# Example:
|
107
|
+
# customer = {
|
108
|
+
# email: "test@example.com",
|
109
|
+
# device_fingerprint_id: "1234",
|
110
|
+
# phone: {country_phone_code: "1", phone_number: "5555555555"},
|
111
|
+
# paypal_app_installed: true,
|
112
|
+
# venmo_app_installed: true,
|
113
|
+
# }
|
114
|
+
# input = Braintree::CustomerRecommendationsInput.new(
|
115
|
+
# session_id: "11EF-34BC-2702904B-9026-555555555555",
|
116
|
+
# customer: customer,
|
117
|
+
# recommendations: [Braintree::Recommendations::PAYMENT_RECOMMENDATIONS]
|
118
|
+
# )
|
119
|
+
# result = gateway.customer_session.get_customer_recommendations(input)
|
120
|
+
# if result.success?
|
121
|
+
# puts "Fetched customer recommendations"
|
122
|
+
# payload = result.customer_recommendations
|
123
|
+
# puts payload
|
124
|
+
# else
|
125
|
+
# puts "Validations failed"
|
126
|
+
# puts result.errors.first.message
|
127
|
+
# end
|
128
|
+
#
|
129
|
+
# @param input [CustomerRecommendationsInput] The input parameters for retrieving customer recommendations.
|
130
|
+
#
|
131
|
+
# @return [Result\Error|Result\Successful] A result object containing the customer recommendations if successful, or errors otherwise.
|
132
|
+
#
|
133
|
+
# @raise [UnexpectedError] If there is an unexpected error during the process.
|
134
|
+
def get_customer_recommendations(customer_recommendations_input)
|
135
|
+
variables = {"input" => customer_recommendations_input.to_graphql_variables}
|
136
|
+
|
137
|
+
begin
|
138
|
+
response = @graphql_client.query(GET_CUSTOMER_RECOMMENDATIONS, variables)
|
139
|
+
errors = GraphQLClient.get_validation_errors(response)
|
140
|
+
if errors
|
141
|
+
ErrorResult.new(@gateway, {errors:errors})
|
142
|
+
else
|
143
|
+
SuccessfulResult.new(:customer_recommendations => extract_customer_recommendations_payload(response))
|
144
|
+
end
|
145
|
+
rescue StandardError => e
|
146
|
+
raise UnexpectedError, e.message
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
private
|
151
|
+
|
152
|
+
def execute_mutation(query, input, operation_name)
|
153
|
+
variables = {"input" => input.to_graphql_variables}
|
154
|
+
begin
|
155
|
+
response = @graphql_client.query(query, variables)
|
156
|
+
errors = GraphQLClient.get_validation_errors(response)
|
157
|
+
if errors
|
158
|
+
ErrorResult.new(@gateway, {errors:errors})
|
159
|
+
else
|
160
|
+
session_id = get_value(response, "data.#{operation_name}.sessionId")
|
161
|
+
SuccessfulResult.new(:session_id => session_id)
|
162
|
+
end
|
163
|
+
rescue StandardError => e
|
164
|
+
raise UnexpectedError, e.message
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
def get_value(response, key)
|
169
|
+
map = response
|
170
|
+
key_parts = key.split(".")
|
171
|
+
|
172
|
+
key_parts[0..-2].each do |sub_key|
|
173
|
+
map = pop_value(map, sub_key)
|
174
|
+
raise UnexpectedError, "Couldn't parse response" unless map.is_a?(Hash)
|
175
|
+
end
|
176
|
+
|
177
|
+
pop_value(map, key_parts.last)
|
178
|
+
end
|
179
|
+
|
180
|
+
def pop_value(map, key)
|
181
|
+
key = key.to_sym
|
182
|
+
if map.key?(key)
|
183
|
+
map[key]
|
184
|
+
else
|
185
|
+
raise UnexpectedError, "Couldn't parse response"
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
def extract_customer_recommendations_payload(data)
|
190
|
+
customer_recommendations_hash = get_value(data, "data.customerRecommendations")
|
191
|
+
Braintree::CustomerRecommendationsPayload._new(customer_recommendations_hash)
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
@@ -12,7 +12,7 @@ module Braintree
|
|
12
12
|
|
13
13
|
def initialize(gateway, data)
|
14
14
|
@gateway = gateway
|
15
|
-
@params = data[:params]
|
15
|
+
@params = data[:params] if data[:params]
|
16
16
|
@credit_card_verification = CreditCardVerification._new(data[:verification]) if data[:verification]
|
17
17
|
@merchant_account = MerchantAccount._new(gateway, data[:merchant_account]) if data[:merchant_account]
|
18
18
|
@message = data[:message]
|
data/lib/braintree/errors.rb
CHANGED
data/lib/braintree/gateway.rb
CHANGED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Represents the input to request the creation of a PayPal customer session.
|
2
|
+
|
3
|
+
module Braintree
|
4
|
+
class CreateCustomerSessionInput
|
5
|
+
include BaseModule
|
6
|
+
|
7
|
+
attr_reader :attrs
|
8
|
+
attr_reader :merchant_account_id
|
9
|
+
attr_reader :session_id
|
10
|
+
attr_reader :customer
|
11
|
+
attr_reader :domain
|
12
|
+
|
13
|
+
def initialize(attributes)
|
14
|
+
@attrs = attributes.keys
|
15
|
+
set_instance_variables_from_hash(attributes)
|
16
|
+
@customer = attributes[:customer] ? CustomerSessionInput.new(attributes[:customer]) : nil
|
17
|
+
end
|
18
|
+
|
19
|
+
def inspect
|
20
|
+
inspected_attributes = @attrs.map { |attr| "#{attr}:#{send(attr).inspect}" }
|
21
|
+
"#<#{self.class} #{inspected_attributes.join(" ")}>"
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_graphql_variables
|
25
|
+
variables = {}
|
26
|
+
variables["merchantAccountId"] = merchant_account_id if merchant_account_id
|
27
|
+
variables["sessionId"] = session_id if session_id
|
28
|
+
variables["domain"] = domain if domain
|
29
|
+
variables["customer"] = customer.to_graphql_variables if customer
|
30
|
+
variables
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# Represents the input to request PayPal customer session recommendations.
|
2
|
+
|
3
|
+
module Braintree
|
4
|
+
class CustomerRecommendationsInput
|
5
|
+
include BaseModule
|
6
|
+
|
7
|
+
attr_reader :attrs
|
8
|
+
attr_reader :merchant_account_id
|
9
|
+
attr_reader :session_id
|
10
|
+
attr_reader :recommendations
|
11
|
+
attr_reader :customer
|
12
|
+
|
13
|
+
def initialize(attributes)
|
14
|
+
unless attributes[:session_id]
|
15
|
+
raise ArgumentError, "Expected hash to contain a :session_id"
|
16
|
+
end
|
17
|
+
unless attributes[:recommendations]
|
18
|
+
raise ArgumentError, "Expected hash to contain a :recommendations"
|
19
|
+
end
|
20
|
+
@attrs = attributes.keys
|
21
|
+
set_instance_variables_from_hash(attributes)
|
22
|
+
@customer = attributes[:customer] ? CustomerSessionInput.new(attributes[:customer]) : nil
|
23
|
+
end
|
24
|
+
|
25
|
+
def inspect
|
26
|
+
inspected_attributes = @attrs.map { |attr| "#{attr}:#{send(attr).inspect}" }
|
27
|
+
"#<#{self.class} #{inspected_attributes.join(" ")}>"
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_graphql_variables
|
31
|
+
variables = {}
|
32
|
+
variables["merchantAccountId"] = merchant_account_id if merchant_account_id
|
33
|
+
variables["sessionId"] = session_id if session_id
|
34
|
+
variables["recommendations"] = recommendations if recommendations
|
35
|
+
variables["customer"] = customer.to_graphql_variables if customer
|
36
|
+
variables
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# Customer identifying information for a PayPal customer session.
|
2
|
+
|
3
|
+
module Braintree
|
4
|
+
class CustomerSessionInput
|
5
|
+
include BaseModule
|
6
|
+
|
7
|
+
attr_reader :attrs
|
8
|
+
attr_reader :email
|
9
|
+
attr_reader :phone
|
10
|
+
attr_reader :device_fingerprint_id
|
11
|
+
attr_reader :paypal_app_installed
|
12
|
+
attr_reader :venmo_app_installed
|
13
|
+
attr_reader :user_agent
|
14
|
+
|
15
|
+
def initialize(attributes)
|
16
|
+
@attrs = attributes.keys
|
17
|
+
set_instance_variables_from_hash(attributes)
|
18
|
+
@phone = attributes[:phone] ? PhoneInput.new(attributes[:phone]) : nil
|
19
|
+
end
|
20
|
+
|
21
|
+
def inspect
|
22
|
+
inspected_attributes = @attrs.map { |attr| "#{attr}:#{send(attr).inspect}" }
|
23
|
+
"#<#{self.class} #{inspected_attributes.join(" ")}>"
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_graphql_variables
|
27
|
+
variables = {}
|
28
|
+
variables["email"] = email if email
|
29
|
+
variables["phone"] = phone.to_graphql_variables if phone
|
30
|
+
variables["deviceFingerprintId"] = device_fingerprint_id if device_fingerprint_id
|
31
|
+
variables["paypalAppInstalled"] = paypal_app_installed if paypal_app_installed
|
32
|
+
variables["venmoAppInstalled"] = venmo_app_installed if venmo_app_installed
|
33
|
+
variables["userAgent"] = user_agent if user_agent
|
34
|
+
variables
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# Phone number input for PayPal customer session.
|
2
|
+
|
3
|
+
module Braintree
|
4
|
+
class PhoneInput
|
5
|
+
include BaseModule
|
6
|
+
|
7
|
+
attr_reader :attrs
|
8
|
+
attr_reader :country_phone_code
|
9
|
+
attr_reader :phone_number
|
10
|
+
attr_reader :extension_number
|
11
|
+
|
12
|
+
def initialize(attributes)
|
13
|
+
@attrs = attributes.keys
|
14
|
+
set_instance_variables_from_hash(attributes)
|
15
|
+
end
|
16
|
+
|
17
|
+
def inspect
|
18
|
+
inspected_attributes = @attrs.map { |attr| "#{attr}:#{send(attr).inspect}" }
|
19
|
+
"#<#{self.class} #{inspected_attributes.join(" ")}>"
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_graphql_variables
|
23
|
+
variables = {}
|
24
|
+
variables["countryPhoneCode"] = country_phone_code if country_phone_code
|
25
|
+
variables["phoneNumber"] = phone_number if phone_number
|
26
|
+
variables["extensionNumber"] = extension_number if extension_number
|
27
|
+
variables
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# Represents the input to request an update to a PayPal customer session.
|
2
|
+
|
3
|
+
module Braintree
|
4
|
+
class UpdateCustomerSessionInput
|
5
|
+
include BaseModule
|
6
|
+
|
7
|
+
attr_reader :attrs
|
8
|
+
attr_reader :merchant_account_id
|
9
|
+
attr_reader :session_id
|
10
|
+
attr_reader :customer
|
11
|
+
|
12
|
+
def initialize(attributes)
|
13
|
+
unless attributes[:session_id]
|
14
|
+
raise ArgumentError, "Expected hash to contain a :session_id"
|
15
|
+
end
|
16
|
+
@attrs = attributes.keys
|
17
|
+
set_instance_variables_from_hash(attributes)
|
18
|
+
@customer = attributes[:customer] ? CustomerSessionInput.new(attributes[:customer]) : nil
|
19
|
+
end
|
20
|
+
|
21
|
+
def inspect
|
22
|
+
inspected_attributes = @attrs.map { |attr| "#{attr}:#{send(attr).inspect}" }
|
23
|
+
"#<#{self.class} #{inspected_attributes.join(" ")}>"
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_graphql_variables
|
27
|
+
variables = {}
|
28
|
+
variables["merchantAccountId"] = merchant_account_id if merchant_account_id
|
29
|
+
variables["sessionId"] = session_id if session_id
|
30
|
+
variables["customer"] = customer.to_graphql_variables if customer
|
31
|
+
variables
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# Represents the customer recommendations information associated with a PayPal customer session.
|
2
|
+
|
3
|
+
module Braintree
|
4
|
+
class CustomerRecommendationsPayload
|
5
|
+
include BaseModule
|
6
|
+
|
7
|
+
attr_reader :attrs
|
8
|
+
attr_reader :is_in_paypal_network
|
9
|
+
attr_reader :recommendations
|
10
|
+
|
11
|
+
def initialize(attributes)
|
12
|
+
@attrs = [:is_in_paypal_network, :recommendations]
|
13
|
+
@is_in_paypal_network = attributes[:isInPayPalNetwork] if attributes[:isInPayPalNetwork]
|
14
|
+
@recommendations = CustomerRecommendations._new(attributes[:recommendations]) if attributes[:recommendations]
|
15
|
+
end
|
16
|
+
|
17
|
+
def inspect
|
18
|
+
inspected_attributes = @attrs.map { |attr| "#{attr}:#{send(attr).inspect}" }
|
19
|
+
"#<#{self.class} #{inspected_attributes.join(" ")}>"
|
20
|
+
end
|
21
|
+
|
22
|
+
class << self
|
23
|
+
protected :new
|
24
|
+
end
|
25
|
+
|
26
|
+
def self._new(*args)
|
27
|
+
self.new(*args)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# Represents the payment method and priority associated with a PayPal customer session.
|
2
|
+
|
3
|
+
module Braintree
|
4
|
+
class PaymentOptions
|
5
|
+
include BaseModule
|
6
|
+
|
7
|
+
attr_reader :attrs
|
8
|
+
attr_reader :payment_option
|
9
|
+
attr_reader :recommended_priority
|
10
|
+
|
11
|
+
def initialize(attributes)
|
12
|
+
@attrs = [:payment_option, :recommended_priority]
|
13
|
+
@payment_option = attributes[:paymentOption] if attributes[:paymentOption]
|
14
|
+
@recommended_priority = attributes[:recommendedPriority] if attributes[:recommendedPriority]
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
def inspect
|
19
|
+
inspected_attributes = @attrs.map { |attr| "#{attr}:#{send(attr).inspect}" }
|
20
|
+
"#<#{self.class} #{inspected_attributes.join(" ")}>"
|
21
|
+
end
|
22
|
+
|
23
|
+
class << self
|
24
|
+
protected :new
|
25
|
+
end
|
26
|
+
|
27
|
+
def self._new(*args)
|
28
|
+
self.new(*args)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# A union of all possible customer recommendations associated with a PayPal customer session.
|
2
|
+
|
3
|
+
module Braintree
|
4
|
+
class CustomerRecommendations
|
5
|
+
include BaseModule
|
6
|
+
|
7
|
+
attr_reader :attrs
|
8
|
+
attr_reader :payment_options
|
9
|
+
|
10
|
+
def initialize(attributes)
|
11
|
+
@attrs = [:payment_options]
|
12
|
+
if attributes.nil?
|
13
|
+
@payment_options = []
|
14
|
+
else
|
15
|
+
@payment_options = (attributes[:paymentOptions] || []).map { |payment_options_hash| PaymentOptions._new(payment_options_hash) }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def inspect
|
20
|
+
inspected_attributes = @attrs.map { |attr| "#{attr}:#{send(attr).inspect}" }
|
21
|
+
"#<#{self.class} #{inspected_attributes.join(" ")}>"
|
22
|
+
end
|
23
|
+
|
24
|
+
class << self
|
25
|
+
protected :new
|
26
|
+
end
|
27
|
+
|
28
|
+
def self._new(*args)
|
29
|
+
self.new(*args)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
|
@@ -30,5 +30,21 @@ module Braintree
|
|
30
30
|
body = Zlib::GzipReader.new(StringIO.new(body)).read if response.header["Content-Encoding"] == "gzip"
|
31
31
|
JSON.parse(body, :symbolize_names => true)
|
32
32
|
end
|
33
|
+
|
34
|
+
def self.get_validation_errors(response)
|
35
|
+
return nil unless response.key?(:errors) && response[:errors].is_a?(Array)
|
36
|
+
validation_errors = response[:errors].map do |error|
|
37
|
+
{
|
38
|
+
:attribute => "",
|
39
|
+
:code => get_validation_error_code(error),
|
40
|
+
:message => error[:message]
|
41
|
+
}
|
42
|
+
end
|
43
|
+
{errors: validation_errors}
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.get_validation_error_code(error)
|
47
|
+
error[:extensions] && error[:extensions][:legacyCode] rescue nil
|
48
|
+
end
|
33
49
|
end
|
34
50
|
end
|
data/lib/braintree/version.rb
CHANGED
data/lib/braintree.rb
CHANGED
@@ -51,6 +51,7 @@ require "braintree/customer"
|
|
51
51
|
require "braintree/customer_gateway"
|
52
52
|
require "braintree/granted_payment_instrument_update"
|
53
53
|
require "braintree/customer_search"
|
54
|
+
require "braintree/customer_session_gateway"
|
54
55
|
require "braintree/descriptor"
|
55
56
|
require "braintree/digest"
|
56
57
|
require "braintree/discount"
|
@@ -75,6 +76,16 @@ require "braintree/exchange_rate_quote_input"
|
|
75
76
|
require "braintree/exchange_rate_quote_response"
|
76
77
|
require "braintree/exchange_rate_quote_request"
|
77
78
|
require "braintree/gateway"
|
79
|
+
require "braintree/graphql/enums/recommendations"
|
80
|
+
require "braintree/graphql/enums/recommended_payment_option"
|
81
|
+
require "braintree/graphql/inputs/create_customer_session_input"
|
82
|
+
require "braintree/graphql/inputs/customer_recommendations_input"
|
83
|
+
require "braintree/graphql/inputs/customer_session_input"
|
84
|
+
require "braintree/graphql/inputs/phone_input"
|
85
|
+
require "braintree/graphql/inputs/update_customer_session_input"
|
86
|
+
require "braintree/graphql/types/customer_recommendations_payload"
|
87
|
+
require "braintree/graphql/types/payment_options"
|
88
|
+
require "braintree/graphql/unions/customer_recommendations"
|
78
89
|
require "braintree/graphql_client"
|
79
90
|
require "braintree/google_pay_card"
|
80
91
|
require "braintree/local_payment_completed"
|