braintree 4.23.0 → 4.34.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/address_gateway.rb +5 -0
- data/lib/braintree/apple_pay_card.rb +6 -0
- data/lib/braintree/bank_account_instant_verification_gateway.rb +38 -0
- data/lib/braintree/bank_account_instant_verification_jwt.rb +23 -0
- data/lib/braintree/bank_account_instant_verification_jwt_request.rb +21 -0
- data/lib/braintree/bin_data.rb +8 -2
- data/lib/braintree/configuration.rb +1 -1
- data/lib/braintree/credit_card.rb +12 -5
- data/lib/braintree/credit_card_gateway.rb +1 -0
- data/lib/braintree/credit_card_verification_gateway.rb +5 -2
- data/lib/braintree/customer_session_gateway.rb +195 -0
- data/lib/braintree/dispute.rb +1 -0
- data/lib/braintree/error_codes.rb +58 -104
- data/lib/braintree/error_result.rb +1 -1
- data/lib/braintree/errors.rb +2 -1
- data/lib/braintree/gateway.rb +12 -0
- data/lib/braintree/google_pay_card.rb +5 -0
- data/lib/braintree/graphql/enums/recommendations.rb +9 -0
- data/lib/braintree/graphql/enums/recommended_payment_option.rb +10 -0
- data/lib/braintree/graphql/inputs/create_customer_session_input.rb +44 -0
- data/lib/braintree/graphql/inputs/customer_recommendations_input.rb +40 -0
- data/lib/braintree/graphql/inputs/customer_session_input.rb +45 -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 +34 -0
- data/lib/braintree/graphql/inputs/update_customer_session_input.rb +42 -0
- data/lib/braintree/graphql/types/customer_recommendations_payload.rb +129 -0
- data/lib/braintree/graphql/types/payment_options.rb +35 -0
- data/lib/braintree/graphql/types/payment_recommendations.rb +35 -0
- data/lib/braintree/graphql/unions/customer_recommendations.rb +47 -0
- data/lib/braintree/graphql_client.rb +16 -0
- data/lib/braintree/merchant_account.rb +1 -25
- data/lib/braintree/merchant_account_gateway.rb +0 -81
- data/lib/braintree/meta_checkout_card.rb +11 -6
- data/lib/braintree/meta_checkout_token.rb +11 -6
- data/lib/braintree/payment_method_gateway.rb +9 -0
- data/lib/braintree/paypal_payment_resource.rb +22 -0
- data/lib/braintree/paypal_payment_resource_gateway.rb +36 -0
- data/lib/braintree/successful_result.rb +3 -0
- data/lib/braintree/test/credit_card.rb +5 -0
- data/lib/braintree/transaction/apple_pay_details.rb +7 -0
- data/lib/braintree/transaction/credit_card_details.rb +22 -10
- data/lib/braintree/transaction/google_pay_details.rb +16 -10
- data/lib/braintree/transaction/meta_checkout_card_details.rb +11 -2
- data/lib/braintree/transaction/meta_checkout_token_details.rb +13 -3
- data/lib/braintree/transaction/paypal_details.rb +2 -0
- data/lib/braintree/transaction/visa_checkout_card_details.rb +10 -2
- data/lib/braintree/transaction.rb +3 -26
- data/lib/braintree/transaction_gateway.rb +52 -31
- data/lib/braintree/us_bank_account_verification.rb +3 -1
- data/lib/braintree/version.rb +1 -1
- data/lib/braintree/visa_checkout_card.rb +10 -5
- data/lib/braintree/webhook_notification.rb +1 -4
- data/lib/braintree/webhook_testing_gateway.rb +16 -33
- data/lib/braintree/xml/{libxml.rb → nokogiri.rb} +18 -16
- data/lib/braintree/xml/parser.rb +4 -4
- data/lib/braintree.rb +21 -4
- data/spec/integration/braintree/advanced_search_spec.rb +7 -4
- data/spec/integration/braintree/apple_pay_spec.rb +6 -7
- data/spec/integration/braintree/bank_account_instant_verification_spec.rb +191 -0
- data/spec/integration/braintree/client_api/spec_helper.rb +81 -0
- data/spec/integration/braintree/credit_card_spec.rb +115 -1
- data/spec/integration/braintree/credit_card_verification_spec.rb +149 -0
- data/spec/integration/braintree/customer_session_spec.rb +154 -0
- data/spec/integration/braintree/customer_spec.rb +94 -10
- data/spec/integration/braintree/disbursement_spec.rb +1 -1
- data/spec/integration/braintree/dispute_spec.rb +13 -2
- data/spec/integration/braintree/merchant_account_spec.rb +19 -359
- data/spec/integration/braintree/merchant_spec.rb +4 -4
- data/spec/integration/braintree/payment_method_nonce_spec.rb +55 -0
- data/spec/integration/braintree/payment_method_spec.rb +57 -7
- data/spec/integration/braintree/payment_method_us_bank_account_spec.rb +0 -3
- data/spec/integration/braintree/paypal_payment_resource_spec.rb +141 -0
- data/spec/integration/braintree/transaction_payment_facilitator_spec.rb +119 -0
- data/spec/integration/braintree/transaction_search_spec.rb +38 -33
- data/spec/integration/braintree/transaction_spec.rb +266 -350
- data/spec/integration/braintree/transaction_transfer_type_spec.rb +325 -0
- data/spec/integration/braintree/transaction_us_bank_account_spec.rb +0 -1
- data/spec/integration/braintree/us_bank_account_spec.rb +0 -3
- data/spec/integration/braintree/us_bank_account_verification_spec.rb +1 -1
- data/spec/spec_helper.rb +46 -12
- data/spec/unit/braintree/apple_pay_card_spec.rb +7 -0
- data/spec/unit/braintree/bank_account_instant_verification_gateway_spec.rb +98 -0
- data/spec/unit/braintree/bank_account_instant_verification_jwt_request_spec.rb +71 -0
- data/spec/unit/braintree/client_token_spec.rb +11 -0
- data/spec/unit/braintree/configuration_spec.rb +1 -1
- data/spec/unit/braintree/credit_card_spec.rb +27 -2
- data/spec/unit/braintree/credit_card_verification_gateway_spec.rb +1 -0
- data/spec/unit/braintree/credit_card_verification_spec.rb +17 -0
- data/spec/unit/braintree/customer_session_gateway_spec.rb +122 -0
- data/spec/unit/braintree/customer_spec.rb +2 -1
- data/spec/unit/braintree/dispute_spec.rb +6 -0
- data/spec/unit/braintree/error_result_spec.rb +28 -0
- data/spec/unit/braintree/google_pay_card_spec.rb +28 -0
- data/spec/unit/braintree/graphql/create_customer_session_input_spec.rb +102 -0
- data/spec/unit/braintree/graphql/customer_recommendations_input_spec.rb +80 -0
- data/spec/unit/braintree/graphql/customer_recommendations_spec.rb +40 -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 +107 -0
- data/spec/unit/braintree/graphql_client_spec.rb +37 -0
- data/spec/unit/braintree/meta_checkout_card_spec.rb +61 -51
- data/spec/unit/braintree/meta_checkout_token_spec.rb +7 -1
- data/spec/unit/braintree/payment_method_nonce_spec.rb +11 -1
- data/spec/unit/braintree/payment_method_spec.rb +12 -0
- data/spec/unit/braintree/paypal_payment_resource_spec.rb +125 -0
- data/spec/unit/braintree/transaction/apple_pay_details_spec.rb +37 -0
- data/spec/unit/braintree/transaction/credit_card_details_spec.rb +15 -1
- data/spec/unit/braintree/transaction/google_pay_details_spec.rb +37 -0
- data/spec/unit/braintree/transaction/meta_checkout_card_details_spec.rb +28 -0
- data/spec/unit/braintree/transaction/meta_checkout_token_details_spec.rb +28 -0
- data/spec/unit/braintree/transaction/paypal_details_spec.rb +5 -0
- data/spec/unit/braintree/transaction/visa_checkout_card_details_spec.rb +28 -0
- data/spec/unit/braintree/transaction_ach_mandate_spec.rb +82 -0
- data/spec/unit/braintree/transaction_gateway_spec.rb +58 -11
- data/spec/unit/braintree/transaction_spec.rb +66 -0
- data/spec/unit/braintree/visa_checkout_card_spec.rb +28 -0
- data/spec/unit/braintree/webhook_notification_spec.rb +15 -51
- data/spec/unit/braintree/xml/{libxml_spec.rb → nokogiri_spec.rb} +7 -7
- data/spec/unit/braintree/xml/parser_spec.rb +57 -0
- data/spec/unit/credit_card_details_spec.rb +28 -0
- metadata +49 -10
- data/lib/braintree/merchant_account/business_details.rb +0 -17
- data/lib/braintree/merchant_account/funding_details.rb +0 -18
- data/lib/braintree/merchant_account/individual_details.rb +0 -20
- data/lib/ssl/securetrust_ca.crt +0 -44
- data/spec/unit/braintree/disbursement_spec.rb +0 -131
- data/spec/unit/braintree/merchant_account_spec.rb +0 -33
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1c3d511f196493254353d03633aedd94e6bc5ac4c0d075ab354a19435ca1e223
|
|
4
|
+
data.tar.gz: dcfc72a09d796a25d40451abe117dda0ea63a2e53874f45de0ee5546b94fc440
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: aa45eeeda00fb2a9d9999c8c2d41a3f9ef4385190598ade9d89ca2017222e893b31e9e3104ed81aa6f03a96bd4f9b0e1247b5e948d2687885eac5e5a0dbd7967
|
|
7
|
+
data.tar.gz: d554568c2653f57c5b69ce9bec05655d84f8aa01b96357b3effda416bc1c1c3a8da473db9930669e3c65b7165d1b4fe131ca5578ed4f396fab201d61cbdf376c
|
|
@@ -84,6 +84,11 @@ module Braintree
|
|
|
84
84
|
def self._update_signature
|
|
85
85
|
_create_signature
|
|
86
86
|
end
|
|
87
|
+
|
|
88
|
+
def self._address_attributes
|
|
89
|
+
[:street_address, :extended_address, :locality, :region, :postal_code, :country_code_alpha2,
|
|
90
|
+
{:international_phone => [:country_code, :national_number]}]
|
|
91
|
+
end
|
|
87
92
|
end
|
|
88
93
|
end
|
|
89
94
|
|
|
@@ -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
|
|
@@ -26,13 +29,16 @@ module Braintree
|
|
|
26
29
|
attr_reader :expired
|
|
27
30
|
attr_reader :healthcare
|
|
28
31
|
attr_reader :image_url
|
|
32
|
+
attr_reader :is_device_token
|
|
29
33
|
attr_reader :issuing_bank
|
|
30
34
|
attr_reader :last_4
|
|
31
35
|
attr_reader :merchant_token_identifier
|
|
32
36
|
attr_reader :payment_instrument_name
|
|
33
37
|
attr_reader :payroll
|
|
34
38
|
attr_reader :prepaid
|
|
39
|
+
attr_reader :prepaid_reloadable
|
|
35
40
|
attr_reader :product_id
|
|
41
|
+
attr_reader :purchase
|
|
36
42
|
attr_reader :source_card_last4
|
|
37
43
|
attr_reader :source_description
|
|
38
44
|
attr_reader :subscriptions
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
module Braintree
|
|
2
|
+
class BankAccountInstantVerificationGateway
|
|
3
|
+
|
|
4
|
+
CREATE_JWT_MUTATION =
|
|
5
|
+
"mutation CreateBankAccountInstantVerificationJwt($input: CreateBankAccountInstantVerificationJwtInput!) { " +
|
|
6
|
+
" createBankAccountInstantVerificationJwt(input: $input) {" +
|
|
7
|
+
" jwt" +
|
|
8
|
+
" }" +
|
|
9
|
+
"}"
|
|
10
|
+
|
|
11
|
+
def initialize(gateway)
|
|
12
|
+
@gateway = gateway
|
|
13
|
+
@config = gateway.config
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def create_jwt(request)
|
|
17
|
+
variables = request.to_graphql_variables
|
|
18
|
+
response = @gateway.graphql_client.query(CREATE_JWT_MUTATION, variables)
|
|
19
|
+
errors = Braintree::GraphQLClient.get_validation_errors(response)
|
|
20
|
+
|
|
21
|
+
if errors
|
|
22
|
+
ErrorResult.new(@gateway, {errors: errors})
|
|
23
|
+
else
|
|
24
|
+
data = response.dig(:data, :createBankAccountInstantVerificationJwt)
|
|
25
|
+
|
|
26
|
+
if data.nil?
|
|
27
|
+
raise UnexpectedError, "expected :createBankAccountInstantVerificationJwt"
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
jwt_attrs = {
|
|
31
|
+
:jwt => data[:jwt]
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
SuccessfulResult.new(:bank_account_instant_verification_jwt => BankAccountInstantVerificationJwt._new(jwt_attrs))
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module Braintree
|
|
2
|
+
class BankAccountInstantVerificationJwt
|
|
3
|
+
include BaseModule
|
|
4
|
+
|
|
5
|
+
attr_reader :jwt
|
|
6
|
+
|
|
7
|
+
def initialize(attributes)
|
|
8
|
+
set_instance_variables_from_hash(attributes)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self._new(*args)
|
|
12
|
+
self.new(*args)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def inspect
|
|
16
|
+
attr_order = [:jwt]
|
|
17
|
+
formatted_attrs = attr_order.map do |attr|
|
|
18
|
+
"#{attr}: #{send(attr).inspect}"
|
|
19
|
+
end
|
|
20
|
+
"#<#{self.class} #{formatted_attrs.join(', ')}>"
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module Braintree
|
|
2
|
+
class BankAccountInstantVerificationJwtRequest
|
|
3
|
+
include BaseModule
|
|
4
|
+
|
|
5
|
+
attr_accessor :business_name, :return_url, :cancel_url
|
|
6
|
+
|
|
7
|
+
def initialize(attributes = {})
|
|
8
|
+
set_instance_variables_from_hash(attributes)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def to_graphql_variables
|
|
12
|
+
variables = {:input => {}}
|
|
13
|
+
|
|
14
|
+
variables[:input][:businessName] = business_name if business_name
|
|
15
|
+
variables[:input][:returnUrl] = return_url if return_url
|
|
16
|
+
variables[:input][:cancelUrl] = cancel_url if cancel_url
|
|
17
|
+
|
|
18
|
+
variables
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
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
|
|
@@ -10,7 +13,9 @@ module Braintree
|
|
|
10
13
|
attr_reader :issuing_bank
|
|
11
14
|
attr_reader :payroll
|
|
12
15
|
attr_reader :prepaid
|
|
16
|
+
attr_reader :prepaid_reloadable
|
|
13
17
|
attr_reader :product_id
|
|
18
|
+
attr_reader :purchase
|
|
14
19
|
|
|
15
20
|
def initialize(attributes)
|
|
16
21
|
set_instance_variables_from_hash attributes unless attributes.nil?
|
|
@@ -25,8 +30,9 @@ module Braintree
|
|
|
25
30
|
|
|
26
31
|
def self._attributes
|
|
27
32
|
[
|
|
28
|
-
:commercial, :
|
|
29
|
-
:issuing_bank, :payroll, :prepaid,
|
|
33
|
+
:business, :commercial, :consumer, :corporate, :country_of_issuance, :debit,
|
|
34
|
+
:durbin_regulated, :healthcare, :issuing_bank, :payroll, :prepaid,
|
|
35
|
+
:prepaid_reloadable, :product_id, :purchase
|
|
30
36
|
]
|
|
31
37
|
end
|
|
32
38
|
end
|
|
@@ -45,14 +45,18 @@ module Braintree
|
|
|
45
45
|
Unknown = "Unknown"
|
|
46
46
|
end
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
IssuingBank =
|
|
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
|
|
@@ -66,7 +70,9 @@ module Braintree
|
|
|
66
70
|
attr_reader :last_4
|
|
67
71
|
attr_reader :payroll
|
|
68
72
|
attr_reader :prepaid
|
|
73
|
+
attr_reader :prepaid_reloadable
|
|
69
74
|
attr_reader :product_id
|
|
75
|
+
attr_reader :purchase
|
|
70
76
|
attr_reader :subscriptions
|
|
71
77
|
attr_reader :token
|
|
72
78
|
attr_reader :unique_number_identifier
|
|
@@ -199,9 +205,10 @@ module Braintree
|
|
|
199
205
|
|
|
200
206
|
def self._attributes
|
|
201
207
|
[
|
|
202
|
-
:billing_address, :bin, :card_type, :cardholder_name, :
|
|
203
|
-
:
|
|
204
|
-
:healthcare, :
|
|
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
|
|
205
212
|
]
|
|
206
213
|
end
|
|
207
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,
|
|
@@ -18,7 +18,8 @@ module Braintree
|
|
|
18
18
|
search = CreditCardVerificationSearch.new
|
|
19
19
|
block.call(search) if block
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
search_params = search.to_hash.merge({:verification_type => ["credit_card"]})
|
|
22
|
+
response = @config.http.post("#{@config.base_merchant_path}/verifications/advanced_search_ids", {:search => search_params})
|
|
22
23
|
ResourceCollection.new(response) { |ids| _fetch_verifications(search, ids) }
|
|
23
24
|
end
|
|
24
25
|
|
|
@@ -39,7 +40,8 @@ module Braintree
|
|
|
39
40
|
|
|
40
41
|
def _fetch_verifications(search, ids)
|
|
41
42
|
search.ids.in ids
|
|
42
|
-
|
|
43
|
+
search_params = search.to_hash.merge({:verification_type => ["credit_card"]})
|
|
44
|
+
response = @config.http.post("#{@config.base_merchant_path}/verifications/advanced_search", {:search => search_params})
|
|
43
45
|
attributes = response[:credit_card_verifications]
|
|
44
46
|
Util.extract_attribute_as_array(attributes, :verification).map { |attrs| CreditCardVerification._new(attrs) }
|
|
45
47
|
end
|
|
@@ -61,6 +63,7 @@ module Braintree
|
|
|
61
63
|
]},
|
|
62
64
|
:intended_transaction_source,
|
|
63
65
|
{:options => [
|
|
66
|
+
:account_information_inquiry,
|
|
64
67
|
:account_type,
|
|
65
68
|
:amount,
|
|
66
69
|
:merchant_account_id,
|
|
@@ -0,0 +1,195 @@
|
|
|
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
|
+
mutation GenerateCustomerRecommendations($input: GenerateCustomerRecommendationsInput!) {
|
|
23
|
+
generateCustomerRecommendations(input: $input) {
|
|
24
|
+
sessionId
|
|
25
|
+
isInPayPalNetwork
|
|
26
|
+
paymentRecommendations {
|
|
27
|
+
paymentOption
|
|
28
|
+
recommendedPriority
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
GRAPHQL
|
|
33
|
+
|
|
34
|
+
def initialize(gateway, graphql_client)
|
|
35
|
+
@gateway = gateway
|
|
36
|
+
@graphql_client = graphql_client
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Creates a new customer session.
|
|
40
|
+
#
|
|
41
|
+
# Example:
|
|
42
|
+
# customer = {
|
|
43
|
+
# email: "test@example.com",
|
|
44
|
+
# device_fingerprint_id: "1234",
|
|
45
|
+
# phone: {country_phone_code: "1", phone_number: "5555555555"},
|
|
46
|
+
# paypal_app_installed: true,
|
|
47
|
+
# venmo_app_installed: true,
|
|
48
|
+
# }
|
|
49
|
+
# input = Braintree::CreateCustomerSessionInput.new(
|
|
50
|
+
# customer: customer,
|
|
51
|
+
# )
|
|
52
|
+
# result = gateway.customer_session.create_customer_session(input)
|
|
53
|
+
# if result.success?
|
|
54
|
+
# puts "Created session #{result.session_id}"
|
|
55
|
+
# else
|
|
56
|
+
# puts "Validations failed"
|
|
57
|
+
# puts result.errors.first.message
|
|
58
|
+
# end
|
|
59
|
+
#
|
|
60
|
+
# @param input [CreateCustomerSessionInput] The input parameters for creating a customer session.
|
|
61
|
+
#
|
|
62
|
+
# @return [(Successful|Error)Result] A result object with session ID if successful, or errors otherwise.
|
|
63
|
+
#
|
|
64
|
+
# @raise [UnexpectedError] If there is an unexpected error during the process.
|
|
65
|
+
def create_customer_session(input)
|
|
66
|
+
execute_mutation(CREATE_CUSTOMER_SESSION, input, :createCustomerSession)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
# Updates an existing customer session.
|
|
71
|
+
#
|
|
72
|
+
# Example:
|
|
73
|
+
# customer = {
|
|
74
|
+
# email: "test@example.com",
|
|
75
|
+
# device_fingerprint_id: "1234",
|
|
76
|
+
# phone: {country_phone_code: "1", phone_number: "5555555555"},
|
|
77
|
+
# paypal_app_installed: true,
|
|
78
|
+
# venmo_app_installed: true,
|
|
79
|
+
# }
|
|
80
|
+
# input = Braintree::UpdateCustomerSessionInput.new(
|
|
81
|
+
# session_id: "11EF-34BC-2702904B-9026-555555555555",
|
|
82
|
+
# customer: customer,
|
|
83
|
+
# )
|
|
84
|
+
# result = gateway.customer_session.updated_customer_session(input)
|
|
85
|
+
# if result.success?
|
|
86
|
+
# puts "Updated session #{result.session_id}"
|
|
87
|
+
# else
|
|
88
|
+
# puts "Validations failed"
|
|
89
|
+
# puts result.errors.first.message
|
|
90
|
+
# end
|
|
91
|
+
#
|
|
92
|
+
# @param input [UpdateCustomerSessionInput] The input parameters for updating a customer session.
|
|
93
|
+
#
|
|
94
|
+
# @return [(Successful|Error)Result] A result object with session ID if successful, or errors otherwise.
|
|
95
|
+
#
|
|
96
|
+
# @raise [UnexpectedError] If there is an unexpected error during the process.
|
|
97
|
+
def update_customer_session(input)
|
|
98
|
+
execute_mutation(UPDATE_CUSTOMER_SESSION, input, :updateCustomerSession)
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
# Retrieves customer recommendations associated with a customer session.
|
|
102
|
+
#
|
|
103
|
+
# Example:
|
|
104
|
+
# customer = {
|
|
105
|
+
# email: "test@example.com",
|
|
106
|
+
# device_fingerprint_id: "1234",
|
|
107
|
+
# phone: {country_phone_code: "1", phone_number: "5555555555"},
|
|
108
|
+
# paypal_app_installed: true,
|
|
109
|
+
# venmo_app_installed: true,
|
|
110
|
+
# }
|
|
111
|
+
# input = Braintree::CustomerRecommendationsInput.new(
|
|
112
|
+
# session_id: "11EF-34BC-2702904B-9026-555555555555",
|
|
113
|
+
# customer: customer,
|
|
114
|
+
# recommendations: [Braintree::Recommendations::PAYMENT_RECOMMENDATIONS]
|
|
115
|
+
# )
|
|
116
|
+
# result = gateway.customer_session.get_customer_recommendations(input)
|
|
117
|
+
# if result.success?
|
|
118
|
+
# puts "Fetched customer recommendations"
|
|
119
|
+
# payload = result.customer_recommendations
|
|
120
|
+
# puts payload
|
|
121
|
+
# else
|
|
122
|
+
# puts "Validations failed"
|
|
123
|
+
# puts result.errors.first.message
|
|
124
|
+
# end
|
|
125
|
+
#
|
|
126
|
+
# @param input [CustomerRecommendationsInput] The input parameters for retrieving customer recommendations.
|
|
127
|
+
#
|
|
128
|
+
# @return [Result\Error|Result\Successful] A result object containing the customer recommendations if successful, or errors otherwise.
|
|
129
|
+
#
|
|
130
|
+
# @raise [UnexpectedError] If there is an unexpected error during the process.
|
|
131
|
+
def get_customer_recommendations(customer_recommendations_input)
|
|
132
|
+
variables = {"input" => customer_recommendations_input.to_graphql_variables}
|
|
133
|
+
|
|
134
|
+
begin
|
|
135
|
+
response = @graphql_client.query(GET_CUSTOMER_RECOMMENDATIONS, variables)
|
|
136
|
+
errors = GraphQLClient.get_validation_errors(response)
|
|
137
|
+
if errors
|
|
138
|
+
ErrorResult.new(@gateway, {errors:errors})
|
|
139
|
+
else
|
|
140
|
+
SuccessfulResult.new(:customer_recommendations => extract_customer_recommendations_payload(response))
|
|
141
|
+
end
|
|
142
|
+
rescue StandardError => e
|
|
143
|
+
if e.message.include?("Authorization failed")
|
|
144
|
+
raise AuthorizationError, e.message
|
|
145
|
+
else
|
|
146
|
+
raise ServerError, e.message
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
private
|
|
152
|
+
|
|
153
|
+
def execute_mutation(query, input, operation_name)
|
|
154
|
+
variables = {"input" => input.to_graphql_variables}
|
|
155
|
+
begin
|
|
156
|
+
response = @graphql_client.query(query, variables)
|
|
157
|
+
errors = GraphQLClient.get_validation_errors(response)
|
|
158
|
+
if errors
|
|
159
|
+
ErrorResult.new(@gateway, {errors:errors})
|
|
160
|
+
else
|
|
161
|
+
session_id = get_value(response, "data.#{operation_name}.sessionId")
|
|
162
|
+
SuccessfulResult.new(:session_id => session_id)
|
|
163
|
+
end
|
|
164
|
+
rescue StandardError => e
|
|
165
|
+
raise UnexpectedError, e.message
|
|
166
|
+
end
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
def get_value(response, key)
|
|
170
|
+
map = response
|
|
171
|
+
key_parts = key.split(".")
|
|
172
|
+
|
|
173
|
+
key_parts[0..-2].each do |sub_key|
|
|
174
|
+
map = pop_value(map, sub_key)
|
|
175
|
+
raise UnexpectedError, "Couldn't parse response" unless map.is_a?(Hash)
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
pop_value(map, key_parts.last)
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
def pop_value(map, key)
|
|
182
|
+
key = key.to_sym
|
|
183
|
+
if map.key?(key)
|
|
184
|
+
map[key]
|
|
185
|
+
else
|
|
186
|
+
raise UnexpectedError, "Couldn't parse response"
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
def extract_customer_recommendations_payload(data)
|
|
191
|
+
customer_recommendations_hash = get_value(data, "data.generateCustomerRecommendations")
|
|
192
|
+
Braintree::CustomerRecommendationsPayload._new({:response => {"generateCustomerRecommendations" => customer_recommendations_hash}})
|
|
193
|
+
end
|
|
194
|
+
end
|
|
195
|
+
end
|
data/lib/braintree/dispute.rb
CHANGED