braintree 4.27.0 → 4.28.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 +4 -4
- data/lib/braintree/apple_pay_card.rb +4 -0
- data/lib/braintree/bin_data.rb +7 -2
- data/lib/braintree/credit_card.rb +11 -5
- data/lib/braintree/credit_card_gateway.rb +1 -0
- data/lib/braintree/credit_card_verification_gateway.rb +1 -0
- data/lib/braintree/customer_session_gateway.rb +11 -10
- data/lib/braintree/google_pay_card.rb +4 -0
- data/lib/braintree/graphql/enums/recommendations.rb +2 -0
- data/lib/braintree/graphql/enums/recommended_payment_option.rb +2 -0
- data/lib/braintree/graphql/inputs/create_customer_session_input.rb +10 -1
- data/lib/braintree/graphql/inputs/customer_recommendations_input.rb +7 -8
- data/lib/braintree/graphql/inputs/customer_session_input.rb +6 -0
- data/lib/braintree/graphql/inputs/monetary_amount_input.rb +28 -0
- data/lib/braintree/graphql/inputs/paypal_payee_input.rb +28 -0
- data/lib/braintree/graphql/inputs/paypal_purchase_unit_input.rb +31 -0
- data/lib/braintree/graphql/inputs/phone_input.rb +2 -0
- data/lib/braintree/graphql/inputs/update_customer_session_input.rb +5 -0
- data/lib/braintree/graphql/types/customer_recommendations_payload.rb +112 -18
- data/lib/braintree/graphql/types/payment_options.rb +2 -0
- data/lib/braintree/graphql/types/payment_recommendations.rb +35 -0
- data/lib/braintree/graphql/unions/customer_recommendations.rb +38 -25
- data/lib/braintree/meta_checkout_card.rb +8 -4
- data/lib/braintree/meta_checkout_token.rb +10 -6
- data/lib/braintree/payment_method_gateway.rb +3 -0
- data/lib/braintree/test/credit_card.rb +4 -0
- data/lib/braintree/transaction/apple_pay_details.rb +4 -0
- data/lib/braintree/transaction/credit_card_details.rb +8 -0
- data/lib/braintree/transaction/google_pay_details.rb +4 -0
- data/lib/braintree/transaction/meta_checkout_card_details.rb +9 -3
- data/lib/braintree/transaction/meta_checkout_token_details.rb +11 -5
- data/lib/braintree/transaction/visa_checkout_card_details.rb +8 -3
- data/lib/braintree/version.rb +1 -1
- data/lib/braintree/visa_checkout_card.rb +9 -4
- data/lib/braintree.rb +4 -0
- data/spec/integration/braintree/credit_card_spec.rb +101 -0
- data/spec/integration/braintree/credit_card_verification_spec.rb +118 -0
- data/spec/integration/braintree/customer_session_spec.rb +59 -49
- data/spec/integration/braintree/customer_spec.rb +71 -4
- data/spec/integration/braintree/payment_method_nonce_spec.rb +44 -0
- data/spec/integration/braintree/payment_method_spec.rb +47 -0
- data/spec/integration/braintree/transaction_spec.rb +61 -25
- data/spec/unit/braintree/apple_pay_card_spec.rb +4 -0
- data/spec/unit/braintree/credit_card_spec.rb +22 -2
- data/spec/unit/braintree/credit_card_verification_gateway_spec.rb +1 -0
- data/spec/unit/braintree/customer_session_gateway_spec.rb +10 -9
- data/spec/unit/braintree/customer_spec.rb +2 -1
- data/spec/unit/braintree/google_pay_card_spec.rb +20 -0
- data/spec/unit/braintree/graphql/create_customer_session_input_spec.rb +25 -4
- data/spec/unit/braintree/graphql/customer_recommendations_input_spec.rb +21 -51
- data/spec/unit/braintree/graphql/customer_recommendations_spec.rb +40 -0
- data/spec/unit/braintree/graphql/update_customer_session_input_spec.rb +21 -7
- data/spec/unit/braintree/meta_checkout_card_spec.rb +8 -0
- data/spec/unit/braintree/meta_checkout_token_spec.rb +4 -0
- data/spec/unit/braintree/payment_method_nonce_spec.rb +9 -2
- data/spec/unit/braintree/payment_method_spec.rb +12 -0
- data/spec/unit/braintree/transaction/apple_pay_details_spec.rb +20 -0
- data/spec/unit/braintree/transaction/credit_card_details_spec.rb +5 -1
- data/spec/unit/braintree/transaction/google_pay_details_spec.rb +20 -0
- data/spec/unit/braintree/transaction/meta_checkout_card_details_spec.rb +20 -0
- data/spec/unit/braintree/transaction/meta_checkout_token_details_spec.rb +20 -0
- data/spec/unit/braintree/transaction/visa_checkout_card_details_spec.rb +20 -0
- data/spec/unit/braintree/transaction_spec.rb +8 -0
- data/spec/unit/braintree/visa_checkout_card_spec.rb +20 -0
- data/spec/unit/credit_card_details_spec.rb +20 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f1eb371a013154345b87d1581d335e2e164844b06cfbc720574cc68819d8839f
|
4
|
+
data.tar.gz: ec7325707abf2ad90b2d17ca390ece11adead95ba1f2e8cd4fb42e78470a225b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76fb4902a1ace12c7b7730bd911296143b941de6b8d0a5cc018f1dba3ecb35c1090b00a3d0387e85cf0a54938d578fb2c29b2cf9c06674556d4509572cb24636
|
7
|
+
data.tar.gz: 404445aad78f100dcec0ece96b1d0e7f7f6103afc869333b23d6754bac28ef70f367ef0b1580f7716a4388f2f36129bcc4dcf3c4c547d70f83da5d6e5ad90b75
|
@@ -12,9 +12,12 @@ module Braintree
|
|
12
12
|
|
13
13
|
attr_reader :billing_address
|
14
14
|
attr_reader :bin
|
15
|
+
attr_reader :business
|
15
16
|
attr_reader :card_type
|
16
17
|
attr_reader :cardholder_name
|
17
18
|
attr_reader :commercial
|
19
|
+
attr_reader :consumer
|
20
|
+
attr_reader :corporate
|
18
21
|
attr_reader :country_of_issuance
|
19
22
|
attr_reader :created_at
|
20
23
|
attr_reader :customer_id
|
@@ -34,6 +37,7 @@ module Braintree
|
|
34
37
|
attr_reader :prepaid
|
35
38
|
attr_reader :prepaid_reloadable
|
36
39
|
attr_reader :product_id
|
40
|
+
attr_reader :purchase
|
37
41
|
attr_reader :source_card_last4
|
38
42
|
attr_reader :source_description
|
39
43
|
attr_reader :subscriptions
|
data/lib/braintree/bin_data.rb
CHANGED
@@ -2,7 +2,10 @@ module Braintree
|
|
2
2
|
class BinData
|
3
3
|
include BaseModule
|
4
4
|
|
5
|
+
attr_reader :business
|
5
6
|
attr_reader :commercial
|
7
|
+
attr_reader :consumer
|
8
|
+
attr_reader :corporate
|
6
9
|
attr_reader :country_of_issuance
|
7
10
|
attr_reader :debit
|
8
11
|
attr_reader :durbin_regulated
|
@@ -12,6 +15,7 @@ module Braintree
|
|
12
15
|
attr_reader :prepaid
|
13
16
|
attr_reader :prepaid_reloadable
|
14
17
|
attr_reader :product_id
|
18
|
+
attr_reader :purchase
|
15
19
|
|
16
20
|
def initialize(attributes)
|
17
21
|
set_instance_variables_from_hash attributes unless attributes.nil?
|
@@ -26,8 +30,9 @@ module Braintree
|
|
26
30
|
|
27
31
|
def self._attributes
|
28
32
|
[
|
29
|
-
:commercial, :
|
30
|
-
:
|
33
|
+
:business, :commercial, :consumer, :corporate, :country_of_issuance, :debit,
|
34
|
+
:durbin_regulated, :healthcare, :issuing_bank, :payroll, :prepaid,
|
35
|
+
:prepaid_reloadable, :product_id, :purchase
|
31
36
|
]
|
32
37
|
end
|
33
38
|
end
|
@@ -45,14 +45,18 @@ module Braintree
|
|
45
45
|
Unknown = "Unknown"
|
46
46
|
end
|
47
47
|
|
48
|
-
Commercial =
|
49
|
-
IssuingBank = Payroll = Prepaid = PrepaidReloadable =
|
48
|
+
Business = Commercial = Consumer = Corporate = CountryOfIssuance = Debit =
|
49
|
+
DurbinRegulated = Healthcare = IssuingBank = Payroll = Prepaid = PrepaidReloadable =
|
50
|
+
ProductId = Purchase = CardTypeIndicator
|
50
51
|
|
51
52
|
attr_reader :billing_address
|
52
53
|
attr_reader :bin
|
54
|
+
attr_reader :business
|
53
55
|
attr_reader :card_type
|
54
56
|
attr_reader :cardholder_name
|
55
57
|
attr_reader :commercial
|
58
|
+
attr_reader :consumer
|
59
|
+
attr_reader :corporate
|
56
60
|
attr_reader :country_of_issuance
|
57
61
|
attr_reader :created_at
|
58
62
|
attr_reader :customer_id
|
@@ -68,6 +72,7 @@ module Braintree
|
|
68
72
|
attr_reader :prepaid
|
69
73
|
attr_reader :prepaid_reloadable
|
70
74
|
attr_reader :product_id
|
75
|
+
attr_reader :purchase
|
71
76
|
attr_reader :subscriptions
|
72
77
|
attr_reader :token
|
73
78
|
attr_reader :unique_number_identifier
|
@@ -200,9 +205,10 @@ module Braintree
|
|
200
205
|
|
201
206
|
def self._attributes
|
202
207
|
[
|
203
|
-
:billing_address, :bin, :card_type, :cardholder_name, :commercial, :
|
204
|
-
:
|
205
|
-
:
|
208
|
+
:billing_address, :bin, :business, :card_type, :cardholder_name, :commercial, :consumer, :corporate,
|
209
|
+
:country_of_issuance, :created_at, :customer_id, :debit, :durbin_regulated, :expiration_month,
|
210
|
+
:expiration_year, :healthcare, :image_url, :is_network_tokenized?, :issuing_bank, :last_4, :payroll,
|
211
|
+
:prepaid, :prepaid_reloadable, :product_id, :purchase, :token, :updated_at
|
206
212
|
]
|
207
213
|
end
|
208
214
|
|
@@ -96,6 +96,7 @@ module Braintree
|
|
96
96
|
# NEXT_MAJOR_VERSION Remove venmo_sdk_session
|
97
97
|
# The old venmo SDK class has been deprecated
|
98
98
|
options = [
|
99
|
+
:account_information_inquiry,
|
99
100
|
:fail_on_duplicate_payment_method,
|
100
101
|
:fail_on_duplicate_payment_method_for_customer,
|
101
102
|
:make_default,
|
@@ -19,16 +19,13 @@ module Braintree
|
|
19
19
|
GRAPHQL
|
20
20
|
|
21
21
|
GET_CUSTOMER_RECOMMENDATIONS = <<~GRAPHQL
|
22
|
-
|
23
|
-
|
22
|
+
mutation GenerateCustomerRecommendations($input: GenerateCustomerRecommendationsInput!) {
|
23
|
+
generateCustomerRecommendations(input: $input) {
|
24
|
+
sessionId
|
24
25
|
isInPayPalNetwork
|
25
|
-
|
26
|
-
... on PaymentRecommendations {
|
27
|
-
paymentOptions {
|
26
|
+
paymentRecommendations {
|
28
27
|
paymentOption
|
29
28
|
recommendedPriority
|
30
|
-
}
|
31
|
-
}
|
32
29
|
}
|
33
30
|
}
|
34
31
|
}
|
@@ -143,7 +140,11 @@ module Braintree
|
|
143
140
|
SuccessfulResult.new(:customer_recommendations => extract_customer_recommendations_payload(response))
|
144
141
|
end
|
145
142
|
rescue StandardError => e
|
146
|
-
|
143
|
+
if e.message.include?("Authorization failed")
|
144
|
+
raise AuthorizationError, e.message
|
145
|
+
else
|
146
|
+
raise ServerError, e.message
|
147
|
+
end
|
147
148
|
end
|
148
149
|
end
|
149
150
|
|
@@ -187,8 +188,8 @@ module Braintree
|
|
187
188
|
end
|
188
189
|
|
189
190
|
def extract_customer_recommendations_payload(data)
|
190
|
-
customer_recommendations_hash = get_value(data, "data.
|
191
|
-
Braintree::CustomerRecommendationsPayload._new(customer_recommendations_hash)
|
191
|
+
customer_recommendations_hash = get_value(data, "data.generateCustomerRecommendations")
|
192
|
+
Braintree::CustomerRecommendationsPayload._new({:response => {"generateCustomerRecommendations" => customer_recommendations_hash}})
|
192
193
|
end
|
193
194
|
end
|
194
195
|
end
|
@@ -3,7 +3,10 @@ module Braintree
|
|
3
3
|
include BaseModule
|
4
4
|
|
5
5
|
attr_reader :bin
|
6
|
+
attr_reader :business
|
6
7
|
attr_reader :commercial
|
8
|
+
attr_reader :consumer
|
9
|
+
attr_reader :corporate
|
7
10
|
attr_reader :country_of_issuance
|
8
11
|
attr_reader :created_at
|
9
12
|
attr_reader :customer_id
|
@@ -20,6 +23,7 @@ module Braintree
|
|
20
23
|
attr_reader :prepaid
|
21
24
|
attr_reader :prepaid_reloadable
|
22
25
|
attr_reader :product_id
|
26
|
+
attr_reader :purchase
|
23
27
|
attr_reader :source_card_last_4
|
24
28
|
attr_reader :source_card_type
|
25
29
|
attr_reader :source_description
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# Represents available types of customer recommendations that can be retrieved using a PayPal customer session.
|
2
2
|
|
3
|
+
#Experimental
|
4
|
+
# This enum is experimental and may change in future releases.
|
3
5
|
module Braintree
|
4
6
|
module Recommendations
|
5
7
|
PAYMENT_RECOMMENDATIONS = "PAYMENT_RECOMMENDATIONS"
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# Represents the input to request the creation of a PayPal customer session.
|
2
2
|
|
3
|
+
#Experimental
|
4
|
+
# This class is experimental and may change in future releases.
|
3
5
|
module Braintree
|
4
6
|
class CreateCustomerSessionInput
|
5
7
|
include BaseModule
|
@@ -9,12 +11,18 @@ module Braintree
|
|
9
11
|
attr_reader :session_id
|
10
12
|
attr_reader :customer
|
11
13
|
attr_reader :domain
|
14
|
+
attr_reader :purchase_units
|
12
15
|
|
13
16
|
def initialize(attributes)
|
14
17
|
@attrs = attributes.keys
|
15
18
|
set_instance_variables_from_hash(attributes)
|
16
19
|
@customer = attributes[:customer] ? CustomerSessionInput.new(attributes[:customer]) : nil
|
17
|
-
|
20
|
+
if attributes[:purchase_units]
|
21
|
+
@purchase_units = attributes[:purchase_units].map do |unit|
|
22
|
+
PayPalPurchaseUnitInput.new(unit)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
18
26
|
|
19
27
|
def inspect
|
20
28
|
inspected_attributes = @attrs.map { |attr| "#{attr}:#{send(attr).inspect}" }
|
@@ -27,6 +35,7 @@ module Braintree
|
|
27
35
|
variables["sessionId"] = session_id if session_id
|
28
36
|
variables["domain"] = domain if domain
|
29
37
|
variables["customer"] = customer.to_graphql_variables if customer
|
38
|
+
variables["purchaseUnits"] = purchase_units.map(&:to_graphql_variables) if purchase_units
|
30
39
|
variables
|
31
40
|
end
|
32
41
|
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# Represents the input to request PayPal customer session recommendations.
|
2
2
|
|
3
|
+
#Experimental
|
4
|
+
# This class is experimental and may change in future releases.
|
3
5
|
module Braintree
|
4
6
|
class CustomerRecommendationsInput
|
5
7
|
include BaseModule
|
@@ -7,19 +9,15 @@ module Braintree
|
|
7
9
|
attr_reader :attrs
|
8
10
|
attr_reader :merchant_account_id
|
9
11
|
attr_reader :session_id
|
10
|
-
attr_reader :recommendations
|
11
12
|
attr_reader :customer
|
13
|
+
attr_reader :purchase_units
|
14
|
+
attr_reader :domain
|
12
15
|
|
13
16
|
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
17
|
@attrs = attributes.keys
|
21
18
|
set_instance_variables_from_hash(attributes)
|
22
19
|
@customer = attributes[:customer] ? CustomerSessionInput.new(attributes[:customer]) : nil
|
20
|
+
@purchase_units = attributes[:purchase_units] ? attributes[:purchase_units].map { |pu| PayPalPurchaseUnitInput.new(pu) } : nil
|
23
21
|
end
|
24
22
|
|
25
23
|
def inspect
|
@@ -31,8 +29,9 @@ module Braintree
|
|
31
29
|
variables = {}
|
32
30
|
variables["merchantAccountId"] = merchant_account_id if merchant_account_id
|
33
31
|
variables["sessionId"] = session_id if session_id
|
34
|
-
variables["recommendations"] = recommendations if recommendations
|
35
32
|
variables["customer"] = customer.to_graphql_variables if customer
|
33
|
+
variables["domain"] = domain if domain
|
34
|
+
variables["purchaseUnits"] = purchase_units.map(&:to_graphql_variables) if purchase_units
|
36
35
|
variables
|
37
36
|
end
|
38
37
|
end
|
@@ -1,12 +1,16 @@
|
|
1
1
|
# Customer identifying information for a PayPal customer session.
|
2
2
|
|
3
|
+
#Experimental
|
4
|
+
# This class is experimental and may change in future releases.
|
3
5
|
module Braintree
|
4
6
|
class CustomerSessionInput
|
5
7
|
include BaseModule
|
6
8
|
|
7
9
|
attr_reader :attrs
|
8
10
|
attr_reader :email
|
11
|
+
attr_reader :hashed_email
|
9
12
|
attr_reader :phone
|
13
|
+
attr_reader :hashed_phone
|
10
14
|
attr_reader :device_fingerprint_id
|
11
15
|
attr_reader :paypal_app_installed
|
12
16
|
attr_reader :venmo_app_installed
|
@@ -26,7 +30,9 @@ module Braintree
|
|
26
30
|
def to_graphql_variables
|
27
31
|
variables = {}
|
28
32
|
variables["email"] = email if email
|
33
|
+
variables["hashedEmail"] = hashed_email if hashed_email
|
29
34
|
variables["phone"] = phone.to_graphql_variables if phone
|
35
|
+
variables["hashedPhone"] = hashed_phone if hashed_phone
|
30
36
|
variables["deviceFingerprintId"] = device_fingerprint_id if device_fingerprint_id
|
31
37
|
variables["paypalAppInstalled"] = paypal_app_installed if paypal_app_installed
|
32
38
|
variables["venmoAppInstalled"] = venmo_app_installed if venmo_app_installed
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#Experimental
|
2
|
+
# This class is experimental and may change in future releases.
|
3
|
+
module Braintree
|
4
|
+
class MonetaryAmountInput
|
5
|
+
include BaseModule
|
6
|
+
|
7
|
+
attr_reader :attrs
|
8
|
+
attr_reader :value
|
9
|
+
attr_reader :currency_code
|
10
|
+
|
11
|
+
def initialize(attributes)
|
12
|
+
@attrs = attributes.keys
|
13
|
+
set_instance_variables_from_hash(attributes)
|
14
|
+
end
|
15
|
+
|
16
|
+
def inspect
|
17
|
+
inspected_attributes = @attrs.map { |attr| "#{attr}:#{send(attr).inspect}" }
|
18
|
+
"#<#{self.class} #{inspected_attributes.join(" ")}>"
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_graphql_variables
|
22
|
+
variables = {}
|
23
|
+
variables["value"] = value if value
|
24
|
+
variables["currencyCode"] = currency_code if currency_code
|
25
|
+
variables
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#Experimental
|
2
|
+
# This class is experimental and may change in future releases.
|
3
|
+
module Braintree
|
4
|
+
class PayPalPayeeInput
|
5
|
+
include BaseModule
|
6
|
+
|
7
|
+
attr_reader :attrs
|
8
|
+
attr_reader :email_address
|
9
|
+
attr_reader :client_id
|
10
|
+
|
11
|
+
def initialize(attributes)
|
12
|
+
@attrs = attributes.keys
|
13
|
+
set_instance_variables_from_hash(attributes)
|
14
|
+
end
|
15
|
+
|
16
|
+
def inspect
|
17
|
+
inspected_attributes = @attrs.map { |attr| "#{attr}:#{send(attr).inspect}" }
|
18
|
+
"#<#{self.class} #{inspected_attributes.join(" ")}>"
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_graphql_variables
|
22
|
+
variables = {}
|
23
|
+
variables["emailAddress"] = email_address if email_address
|
24
|
+
variables["clientId"] = client_id if client_id
|
25
|
+
variables
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
#Experimental
|
2
|
+
# This class is experimental and may change in future releases.
|
3
|
+
module Braintree
|
4
|
+
class PayPalPurchaseUnitInput
|
5
|
+
include BaseModule
|
6
|
+
|
7
|
+
attr_reader :attrs
|
8
|
+
attr_reader :amount
|
9
|
+
attr_reader :payee
|
10
|
+
|
11
|
+
def initialize(attributes)
|
12
|
+
@attrs = attributes.keys
|
13
|
+
unless attributes[:amount]
|
14
|
+
raise ArgumentError, "Expected hash to contain a :amount"
|
15
|
+
end
|
16
|
+
set_instance_variables_from_hash(attributes)
|
17
|
+
@payee = attributes[:payee] ? PayPalPayeeInput.new(attributes[:payee]) : nil
|
18
|
+
@amount = attributes[:amount] ? MonetaryAmountInput.new(attributes[:amount]) : nil
|
19
|
+
end
|
20
|
+
def inspect
|
21
|
+
inspected_attributes = @attrs.map { |attr| "#{attr}:#{send(attr).inspect}" }
|
22
|
+
"#<#{self.class} #{inspected_attributes.join(" ")}>"
|
23
|
+
end
|
24
|
+
def to_graphql_variables
|
25
|
+
variables = {}
|
26
|
+
variables["amount"] = amount.to_graphql_variables if amount
|
27
|
+
variables["payee"] = payee.to_graphql_variables if payee
|
28
|
+
variables
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# Represents the input to request an update to a PayPal customer session.
|
2
2
|
|
3
|
+
#Experimental
|
4
|
+
# This class is experimental and may change in future releases.
|
3
5
|
module Braintree
|
4
6
|
class UpdateCustomerSessionInput
|
5
7
|
include BaseModule
|
@@ -8,6 +10,7 @@ module Braintree
|
|
8
10
|
attr_reader :merchant_account_id
|
9
11
|
attr_reader :session_id
|
10
12
|
attr_reader :customer
|
13
|
+
attr_reader :purchase_units
|
11
14
|
|
12
15
|
def initialize(attributes)
|
13
16
|
unless attributes[:session_id]
|
@@ -16,6 +19,7 @@ module Braintree
|
|
16
19
|
@attrs = attributes.keys
|
17
20
|
set_instance_variables_from_hash(attributes)
|
18
21
|
@customer = attributes[:customer] ? CustomerSessionInput.new(attributes[:customer]) : nil
|
22
|
+
@purchase_units = attributes[:purchase_units] ? attributes[:purchase_units].map { |pu| PayPalPurchaseUnitInput.new(pu) } : nil
|
19
23
|
end
|
20
24
|
|
21
25
|
def inspect
|
@@ -28,6 +32,7 @@ module Braintree
|
|
28
32
|
variables["merchantAccountId"] = merchant_account_id if merchant_account_id
|
29
33
|
variables["sessionId"] = session_id if session_id
|
30
34
|
variables["customer"] = customer.to_graphql_variables if customer
|
35
|
+
variables["purchaseUnits"] = purchase_units.map(&:to_graphql_variables) if purchase_units
|
31
36
|
variables
|
32
37
|
end
|
33
38
|
|
@@ -1,32 +1,126 @@
|
|
1
1
|
# Represents the customer recommendations information associated with a PayPal customer session.
|
2
2
|
|
3
|
+
#Experimental
|
4
|
+
# This class is experimental and may change in future releases.
|
3
5
|
module Braintree
|
4
|
-
|
5
|
-
|
6
|
+
class CustomerRecommendationsPayload
|
7
|
+
include BaseModule
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
|
9
|
+
attr_reader :attrs
|
10
|
+
attr_reader :is_in_paypal_network
|
11
|
+
attr_reader :recommendations
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
@is_in_paypal_network = attributes[:isInPayPalNetwork] if attributes[:isInPayPalNetwork]
|
14
|
-
@recommendations = CustomerRecommendations._new(attributes[:recommendations]) if attributes[:recommendations]
|
15
|
-
end
|
13
|
+
def initialize(attributes)
|
14
|
+
@attrs = [:is_in_paypal_network, :recommendations]
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
if attributes.key?(:response)
|
17
|
+
response = attributes[:response]
|
18
|
+
# Constructor for response map
|
19
|
+
begin
|
20
|
+
@is_in_paypal_network = _get_value(response, "generateCustomerRecommendations.isInPayPalNetwork")
|
21
|
+
@recommendations = _extract_recommendations(response)
|
22
|
+
rescue => e
|
23
|
+
puts e.backtrace.join("\n")
|
24
|
+
raise
|
20
25
|
end
|
26
|
+
else
|
27
|
+
@is_in_paypal_network = attributes[:is_in_paypal_network]
|
28
|
+
@recommendations = attributes[:recommendations]
|
29
|
+
end
|
30
|
+
end
|
21
31
|
|
22
|
-
|
23
|
-
|
24
|
-
|
32
|
+
def _extract_recommendations(response)
|
33
|
+
begin
|
34
|
+
payment_recommendations = _get_value(response, "generateCustomerRecommendations.paymentRecommendations")
|
35
|
+
|
36
|
+
payment_options_list = []
|
37
|
+
payment_recommendations_list = []
|
38
|
+
|
39
|
+
payment_recommendations.each_with_index do |recommendation, _i|
|
40
|
+
recommended_priority = _get_value(recommendation, "recommendedPriority")
|
41
|
+
payment_option_string = _get_value(recommendation, "paymentOption")
|
42
|
+
|
43
|
+
begin
|
44
|
+
payment_option = payment_option_string
|
45
|
+
|
46
|
+
payment_option_obj = Braintree::PaymentOptions._new({
|
47
|
+
paymentOption: payment_option,
|
48
|
+
recommendedPriority: recommended_priority
|
49
|
+
})
|
25
50
|
|
26
|
-
|
27
|
-
|
51
|
+
payment_recommendation_obj = Braintree::PaymentRecommendations._new({
|
52
|
+
paymentOption: payment_option,
|
53
|
+
recommendedPriority: recommended_priority
|
54
|
+
})
|
55
|
+
|
56
|
+
payment_options_list << payment_option_obj
|
57
|
+
payment_recommendations_list << payment_recommendation_obj
|
58
|
+
rescue => e
|
59
|
+
puts e.backtrace.join("\n")
|
60
|
+
raise
|
61
|
+
end
|
28
62
|
end
|
63
|
+
|
64
|
+
customer_recommendations = CustomerRecommendations._new({
|
65
|
+
payment_recommendations: payment_recommendations_list
|
66
|
+
})
|
67
|
+
|
68
|
+
return customer_recommendations
|
69
|
+
rescue => e
|
70
|
+
puts e.backtrace.join("\n")
|
71
|
+
raise ServerError.new("Error extracting recommendations: #{e.message}")
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def _get_value(response, key)
|
76
|
+
current_map = response
|
77
|
+
key_parts = key.split(".")
|
78
|
+
|
79
|
+
# Navigate through nested dictionaries for all but last key
|
80
|
+
(0...key_parts.length - 1).each do |i|
|
81
|
+
sub_key = key_parts[i]
|
82
|
+
current_map = _pop_value(current_map, sub_key)
|
83
|
+
end
|
84
|
+
|
85
|
+
# Get the final value
|
86
|
+
last_key = key_parts[-1]
|
87
|
+
value = _pop_value(current_map, last_key)
|
88
|
+
return value
|
89
|
+
end
|
90
|
+
|
91
|
+
def _pop_value(response, key)
|
92
|
+
|
93
|
+
# Try as string first
|
94
|
+
if response.key?(key)
|
95
|
+
return response[key]
|
96
|
+
end
|
97
|
+
|
98
|
+
# Then try as symbol
|
99
|
+
symkey = key.to_sym
|
100
|
+
if response.key?(symkey)
|
101
|
+
return response[symkey]
|
102
|
+
end
|
103
|
+
|
104
|
+
# Finally try as string with string keys
|
105
|
+
if response.key?(key.to_s)
|
106
|
+
return response[key.to_s]
|
107
|
+
end
|
108
|
+
|
109
|
+
raise ServerError.new("Couldn't parse response")
|
110
|
+
end
|
111
|
+
def inspect
|
112
|
+
inspected_attributes = @attrs.map { |attr| "#{attr}:#{send(attr).inspect}" }
|
113
|
+
"#<#{self.class} #{inspected_attributes.join(" ")}>"
|
114
|
+
end
|
115
|
+
|
116
|
+
class << self
|
117
|
+
protected :new
|
118
|
+
end
|
119
|
+
|
120
|
+
def self._new(*args)
|
121
|
+
self.new(*args)
|
29
122
|
end
|
123
|
+
end
|
30
124
|
end
|
31
125
|
|
32
126
|
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# Represents the payment method and priority associated with a PayPal customer session.
|
2
|
+
|
3
|
+
#Experimental
|
4
|
+
# This class is experimental and may change in future releases.
|
5
|
+
module Braintree
|
6
|
+
class PaymentRecommendations
|
7
|
+
include BaseModule
|
8
|
+
|
9
|
+
attr_reader :attrs
|
10
|
+
attr_reader :payment_option
|
11
|
+
attr_reader :recommended_priority
|
12
|
+
|
13
|
+
def initialize(attributes)
|
14
|
+
@attrs = [:payment_option, :recommended_priority]
|
15
|
+
@payment_option = attributes[:paymentOption] if attributes[:paymentOption]
|
16
|
+
@recommended_priority = attributes[:recommendedPriority] if attributes[:recommendedPriority]
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
def inspect
|
21
|
+
inspected_attributes = @attrs.map { |attr| "#{attr}:#{send(attr).inspect}" }
|
22
|
+
"#<#{self.class} #{inspected_attributes.join(" ")}>"
|
23
|
+
end
|
24
|
+
|
25
|
+
class << self
|
26
|
+
protected :new
|
27
|
+
end
|
28
|
+
|
29
|
+
def self._new(*args)
|
30
|
+
self.new(*args)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
|