braintree 4.4.0 → 4.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d7279d06aef254f1954bf7b8801e4717aa258f7413f05f1c076fbb6f1e2258c5
4
- data.tar.gz: 9b136fbc93fa3f251972a44b0728244f746ef1868507cb40385780cd2137ff22
3
+ metadata.gz: fb259ba1474b20f411b4046f978a7397599c88217b9f1b1a41a969036ca350fa
4
+ data.tar.gz: 4d5dbdf190c5088dca938bf4ecae614db1d1e94f9eb921284523b604686667c9
5
5
  SHA512:
6
- metadata.gz: d611127df5091cb248b434285a2cd2c5080749515d60beba2a00af28809106dca11a4b5607f8774ac111d8115e5bbc85965817ba8fb45e309bbb2ecb8b8e4382
7
- data.tar.gz: c7f547f0a2b62aa36b94e2f410e3375d1b4a2d3d7e76c570f3c9d387c15299a8ed858237db461de7f1889b5552e4c85dd1cedd42ce741c2360eeb38b71ef87c3
6
+ metadata.gz: 8b09ef27dc9c38dd0fc3fb03ec487f7d52112629043af3fb4c760274b267767f08e2b1052bbb2d4f67d0ebade4fe7dae0dfde850a3eca1e0114a15219f988204
7
+ data.tar.gz: 6f5223eb5b90f99f9381245a580f766383102146daa4e095cf1e7f413f592ba9fac78f8cdd67b59a149d4c0a0a9c02d80f3a2650fa2187e2eab54443a24bd045
data/braintree.gemspec CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
18
18
  "bug_tracker_uri" => "https://github.com/braintree/braintree_ruby/issues",
19
19
  "changelog_uri" => "https://github.com/braintree/braintree_ruby/blob/master/CHANGELOG.md",
20
20
  "source_code_uri" => "https://github.com/braintree/braintree_ruby",
21
- "documentation_uri" => "https://developers.braintreepayments.com/"
21
+ "documentation_uri" => "https://developer.paypal.com/braintree/docs"
22
22
  }
23
23
  end
24
24
 
@@ -0,0 +1,21 @@
1
+ module Braintree
2
+ class EnrichedCustomerData
3
+ include BaseModule
4
+
5
+ attr_reader :fields_updated
6
+ attr_reader :profile_data
7
+
8
+ def initialize(attributes) # :nodoc:
9
+ set_instance_variables_from_hash(attributes)
10
+ @profile_data = VenmoProfileData._new(attributes[:profile_data])
11
+ end
12
+
13
+ class << self
14
+ protected :new
15
+ end
16
+
17
+ def self._new(*args) # :nodoc:
18
+ self.new(*args)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,24 @@
1
+ module Braintree
2
+ class PaymentMethodCustomerDataUpdatedMetadata
3
+ include BaseModule
4
+
5
+ attr_reader :token
6
+ attr_reader :payment_method
7
+ attr_reader :datetime_updated
8
+ attr_reader :enriched_customer_data
9
+
10
+ def initialize(gateway, attributes) # :nodoc:
11
+ set_instance_variables_from_hash(attributes)
12
+ @payment_method = PaymentMethodParser.parse_payment_method(gateway, attributes[:payment_method])
13
+ @enriched_customer_data = EnrichedCustomerData._new(enriched_customer_data) if enriched_customer_data
14
+ end
15
+
16
+ class << self
17
+ protected :new
18
+ end
19
+
20
+ def self._new(*args) # :nodoc:
21
+ self.new(*args)
22
+ end
23
+ end
24
+ end
@@ -33,6 +33,26 @@ module Braintree
33
33
 
34
34
  class << self
35
35
  protected :new
36
+
37
+ def create(*args)
38
+ Configuration.gateway.plan.create(*args)
39
+ end
40
+
41
+ def create!(*args)
42
+ Configuration.gateway.plan.create!(*args)
43
+ end
44
+
45
+ def find(*args)
46
+ Configuration.gateway.plan.find(*args)
47
+ end
48
+
49
+ def update(*args)
50
+ Configuration.gateway.plan.update(*args)
51
+ end
52
+
53
+ def update!(*args)
54
+ Configuration.gateway.plan.update!(*args)
55
+ end
36
56
  end
37
57
 
38
58
  def self._new(*args)
@@ -1,5 +1,7 @@
1
1
  module Braintree
2
2
  class PlanGateway # :nodoc:
3
+ include BaseModule
4
+
3
5
  def initialize(gateway)
4
6
  @gateway = gateway
5
7
  @config = gateway.config
@@ -13,5 +15,103 @@ module Braintree
13
15
  Plan._new(@gateway, attributes)
14
16
  end
15
17
  end
18
+
19
+ def create(attributes)
20
+ Util.verify_keys(PlanGateway._create_signature, attributes)
21
+ _do_create "/plans", :plan => attributes
22
+ end
23
+
24
+ def create!(*args)
25
+ return_object_or_raise(:plan) { create(*args) }
26
+ end
27
+
28
+ def find(id)
29
+ raise ArgumentError if id.nil? || id.to_s.strip == ""
30
+ response = @config.http.get("#{@config.base_merchant_path}/plans/#{id}")
31
+ Plan._new(@gateway, response[:plan])
32
+ rescue NotFoundError
33
+ raise NotFoundError, "plan with id #{id.inspect} not found"
34
+ end
35
+
36
+ def update(plan_id, attributes)
37
+ Util.verify_keys(PlanGateway._update_signature, attributes)
38
+ response = @config.http.put("#{@config.base_merchant_path}/plans/#{plan_id}", :plan => attributes)
39
+ if response[:plan]
40
+ SuccessfulResult.new(:plan => Plan._new(@gateway, response[:plan]))
41
+ elsif response[:api_error_response]
42
+ ErrorResult.new(@gateway, response[:api_error_response])
43
+ else
44
+ raise UnexpectedError, "expected :plan or :api_error_response"
45
+ end
46
+ end
47
+
48
+ def update!(*args)
49
+ return_object_or_raise(:plan) { update(*args) }
50
+ end
51
+
52
+ def self._create_signature
53
+ [
54
+ :billing_day_of_month,
55
+ :billing_frequency,
56
+ :currency_iso_code,
57
+ :description,
58
+ :id,
59
+ :merchant_id,
60
+ :name,
61
+ :number_of_billing_cycles,
62
+ :price,
63
+ :trial_duration,
64
+ :trial_duration_unit,
65
+ :trial_period
66
+ ] + _add_on_discount_signature
67
+ end
68
+
69
+ def self._update_signature
70
+ [
71
+ :billing_day_of_month,
72
+ :billing_frequency,
73
+ :currency_iso_code,
74
+ :description,
75
+ :id,
76
+ :merchant_id,
77
+ :name,
78
+ :number_of_billing_cycles,
79
+ :price,
80
+ :trial_duration,
81
+ :trial_duration_unit,
82
+ :trial_period
83
+ ] + _add_on_discount_signature
84
+ end
85
+
86
+ def self._add_on_discount_signature
87
+ [
88
+ {
89
+ :add_ons => [
90
+ {:add => [:amount, :inherited_from_id, :never_expires, :number_of_billing_cycles, :quantity]},
91
+ {:update => [:amount, :existing_id, :never_expires, :number_of_billing_cycles, :quantity]},
92
+ {:remove => [:_any_key_]}
93
+ ]
94
+ },
95
+ {
96
+ :discounts => [
97
+ {:add => [:amount, :inherited_from_id, :never_expires, :number_of_billing_cycles, :quantity]},
98
+ {:update => [:amount, :existing_id, :never_expires, :number_of_billing_cycles, :quantity]},
99
+ {:remove => [:_any_key_]}
100
+ ]
101
+ }
102
+ ]
103
+ end
104
+
105
+ def _do_create(path, params) # :nodoc:
106
+ response = @config.http.post("#{@config.base_merchant_path}#{path}", params)
107
+ if response[:plan]
108
+ SuccessfulResult.new(:plan => Plan._new(@gateway, response[:plan]))
109
+ elsif response[:errors]
110
+ ErrorResult.new(@gateway, response[:errors])
111
+ else
112
+ raise UnexpectedError, "expected :plan or :errors"
113
+ end
114
+ end
16
115
  end
17
116
  end
117
+
@@ -16,6 +16,7 @@ module Braintree
16
16
  attr_reader :payment_method
17
17
  attr_reader :payment_method_nonce
18
18
  attr_reader :paypal_account
19
+ attr_reader :plan
19
20
  attr_reader :settlement_batch_summary
20
21
  attr_reader :subscription
21
22
  attr_reader :supported_networks
@@ -91,6 +91,7 @@ module Braintree
91
91
  end
92
92
 
93
93
  attr_reader :acquirer_reference_number
94
+ attr_reader :ach_return_code
94
95
  attr_reader :add_ons
95
96
  attr_reader :additional_processor_response # The raw response from the processor.
96
97
  attr_reader :amount
@@ -146,6 +147,7 @@ module Braintree
146
147
  attr_reader :refund_ids
147
148
  attr_reader :refunded_transaction_id
148
149
  attr_reader :refunded_installments
150
+ attr_reader :retried
149
151
  attr_reader :retrieval_reference_number
150
152
  attr_reader :risk_data
151
153
  attr_reader :samsung_pay_card_details
@@ -0,0 +1,18 @@
1
+ module Braintree
2
+ class TransactionReview
3
+ include BaseModule
4
+
5
+ attr_reader :transaction_id, :decision, :reviewer_email, :reviewer_note, :reviewer_time
6
+
7
+ def initialize(attributes)
8
+ set_instance_variables_from_hash(attributes)
9
+ end
10
+
11
+ class << self
12
+ protected :new
13
+ def _new(*args) # :nodoc:
14
+ self.new(*args)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,23 @@
1
+ module Braintree
2
+ class VenmoProfileData
3
+ include BaseModule
4
+
5
+ attr_reader :username
6
+ attr_reader :first_name
7
+ attr_reader :last_name
8
+ attr_reader :phone_number
9
+ attr_reader :email
10
+
11
+ def initialize(attributes) # :nodoc:
12
+ set_instance_variables_from_hash(attributes)
13
+ end
14
+
15
+ class << self
16
+ protected :new
17
+ end
18
+
19
+ def self._new(*args) # :nodoc:
20
+ self.new(*args)
21
+ end
22
+ end
23
+ end
@@ -1,7 +1,7 @@
1
1
  module Braintree
2
2
  module Version
3
3
  Major = 4
4
- Minor = 4
4
+ Minor = 7
5
5
  Tiny = 0
6
6
 
7
7
  String = "#{Major}.#{Minor}.#{Tiny}"
@@ -38,6 +38,8 @@ module Braintree
38
38
  PartnerMerchantDisconnected = "partner_merchant_disconnected"
39
39
  PartnerMerchantDeclined = "partner_merchant_declined"
40
40
 
41
+ PaymentMethodCustomerDataUpdated = "payment_method_customer_data_updated"
42
+
41
43
  PaymentMethodRevokedByCustomer = "payment_method_revoked_by_customer"
42
44
 
43
45
  RecipientUpdatedGrantedPaymentMethod = "recipient_updated_granted_payment_method"
@@ -54,6 +56,7 @@ module Braintree
54
56
  SubMerchantAccountDeclined = "sub_merchant_account_declined"
55
57
 
56
58
  TransactionDisbursed = "transaction_disbursed"
59
+ TransactionReviewed = "transaction_reviewed"
57
60
  TransactionSettlementDeclined = "transaction_settlement_declined"
58
61
  TransactionSettled = "transaction_settled"
59
62
  end
@@ -72,10 +75,12 @@ module Braintree
72
75
  attr_reader :local_payment_reversed
73
76
  attr_reader :oauth_access_revocation
74
77
  attr_reader :partner_merchant
78
+ attr_reader :payment_method_customer_data_updated_metadata
75
79
  attr_reader :source_merchant_id
76
80
  attr_reader :subscription
77
81
  attr_reader :timestamp
78
82
  attr_reader :transaction
83
+ attr_reader :transaction_review
79
84
 
80
85
  def self.parse(*args)
81
86
  Configuration.gateway.webhook_notification.parse(*args)
@@ -94,6 +99,7 @@ module Braintree
94
99
  @oauth_access_revocation = OpenStruct.new(@subject[:oauth_application_revocation]) if @subject.has_key?(:oauth_application_revocation)
95
100
  @subscription = Subscription._new(gateway, @subject[:subscription]) if @subject.has_key?(:subscription)
96
101
  @transaction = Transaction._new(gateway, @subject[:transaction]) if @subject.has_key?(:transaction)
102
+ @transaction_review = OpenStruct.new(@subject[:transaction_review]) if @subject.has_key?(:transaction_review)
97
103
  @disbursement = Disbursement._new(gateway, @subject[:disbursement]) if @subject.has_key?(:disbursement)
98
104
  @dispute = Dispute._new(@subject[:dispute]) if @subject.has_key?(:dispute)
99
105
  @account_updater_daily_report = AccountUpdaterDailyReport._new(@subject[:account_updater_daily_report]) if @subject.has_key?(:account_updater_daily_report)
@@ -105,6 +111,8 @@ module Braintree
105
111
  @local_payment_expired = LocalPaymentExpired._new(@subject[:local_payment_expired]) if @subject.has_key?(:local_payment_expired) && Kind::LocalPaymentExpired == @kind
106
112
  @local_payment_funded = LocalPaymentFunded._new(@subject[:local_payment_funded]) if @subject.has_key?(:local_payment_funded) && Kind::LocalPaymentFunded == @kind
107
113
  @local_payment_reversed = LocalPaymentReversed._new(@subject[:local_payment_reversed]) if @subject.has_key?(:local_payment_reversed) && Kind::LocalPaymentReversed == @kind
114
+ @payment_method_customer_data_updated_metadata = PaymentMethodCustomerDataUpdatedMetadata._new(gateway, @subject[:payment_method_customer_data_updated_metadata]) if @subject.has_key?(:payment_method_customer_data_updated_metadata) && Kind::PaymentMethodCustomerDataUpdated == @kind
115
+
108
116
  end
109
117
 
110
118
  def merchant_account
@@ -60,6 +60,8 @@ module Braintree
60
60
  _merchant_account_declined_sample_xml(id)
61
61
  when Braintree::WebhookNotification::Kind::TransactionDisbursed
62
62
  _transaction_disbursed_sample_xml(id)
63
+ when Braintree::WebhookNotification::Kind::TransactionReviewed
64
+ _transaction_reviewed_sample_xml(id)
63
65
  when Braintree::WebhookNotification::Kind::TransactionSettled
64
66
  _transaction_settled_sample_xml(id)
65
67
  when Braintree::WebhookNotification::Kind::TransactionSettlementDeclined
@@ -94,6 +96,8 @@ module Braintree
94
96
  _local_payment_funded_sample_xml(id)
95
97
  when Braintree::WebhookNotification::Kind::LocalPaymentReversed
96
98
  _local_payment_reversed_sample_xml
99
+ when Braintree::WebhookNotification::Kind::PaymentMethodCustomerDataUpdated
100
+ _payment_method_customer_data_updated_sample_xml(id)
97
101
  else
98
102
  _subscription_sample_xml(id)
99
103
  end
@@ -248,6 +252,19 @@ module Braintree
248
252
  XML
249
253
  end
250
254
 
255
+ def _transaction_reviewed_sample_xml(id)
256
+
257
+ <<-XML
258
+ <transaction-review>
259
+ <transaction-id>my_id</transaction-id>
260
+ <decision>decision</decision>
261
+ <reviewer-email>hey@girl.com</reviewer-email>
262
+ <reviewer-note>i reviewed this</reviewer-note>
263
+ <reviewed-time type="datetime">2017-06-16T20:44:41Z</reviewed-time>
264
+ </transaction-review>
265
+ XML
266
+ end
267
+
251
268
  def _transaction_settled_sample_xml(id)
252
269
  <<-XML
253
270
  <transaction>
@@ -884,21 +901,7 @@ module Braintree
884
901
  end
885
902
 
886
903
  def _granted_payment_method_revoked_xml(id)
887
- <<-XML
888
- <venmo-account>
889
- <created-at type='dateTime'>2018-10-11T21:28:37Z</created-at>
890
- <updated-at type='dateTime'>2018-10-11T21:28:37Z</updated-at>
891
- <default type='boolean'>true</default>
892
- <image-url>https://assets.braintreegateway.com/payment_method_logo/venmo.png?environment=test</image-url>
893
- <token>#{id}</token>
894
- <source-description>Venmo Account: venmojoe</source-description>
895
- <username>venmojoe</username>
896
- <venmo-user-id>456</venmo-user-id>
897
- <subscriptions type='array'/>
898
- <customer-id>venmo_customer_id</customer-id>
899
- <global-id>cGF5bWVudG1ldGhvZF92ZW5tb2FjY291bnQ</global-id>
900
- </venmo-account>
901
- XML
904
+ _venmo_account_xml(id)
902
905
  end
903
906
 
904
907
  def _payment_method_revoked_by_customer_sample_xml(id)
@@ -971,5 +974,47 @@ module Braintree
971
974
  </local-payment-reversed>
972
975
  XML
973
976
  end
977
+
978
+ def _payment_method_customer_data_updated_sample_xml(id)
979
+ <<-XML
980
+ <payment-method-customer-data-updated-metadata>
981
+ <token>TOKEN-12345</token>
982
+ <payment-method>
983
+ #{_venmo_account_xml(id)}
984
+ </payment-method>
985
+ <datetime-updated type='dateTime'>2022-01-01T21:28:37Z</datetime-updated>
986
+ <enriched-customer-data>
987
+ <fields-updated type='array'>
988
+ <item>username</item>
989
+ </fields-updated>
990
+ <profile-data>
991
+ <username>venmo_username</username>
992
+ <first-name>John</first-name>
993
+ <last-name>Doe</last-name>
994
+ <phone-number>1231231234</phone-number>
995
+ <email>john.doe@paypal.com</email>
996
+ </profile-data>
997
+ </enriched-customer-data>
998
+ </payment-method-customer-data-updated-metadata>
999
+ XML
1000
+ end
1001
+
1002
+ def _venmo_account_xml(id)
1003
+ <<-XML
1004
+ <venmo-account>
1005
+ <created-at type='dateTime'>2018-10-11T21:28:37Z</created-at>
1006
+ <updated-at type='dateTime'>2018-10-11T21:28:37Z</updated-at>
1007
+ <default type='boolean'>true</default>
1008
+ <image-url>https://assets.braintreegateway.com/payment_method_logo/venmo.png?environment=test</image-url>
1009
+ <token>#{id}</token>
1010
+ <source-description>Venmo Account: venmojoe</source-description>
1011
+ <username>venmojoe</username>
1012
+ <venmo-user-id>456</venmo-user-id>
1013
+ <subscriptions type='array'/>
1014
+ <customer-id>venmo_customer_id</customer-id>
1015
+ <global-id>cGF5bWVudG1ldGhvZF92ZW5tb2FjY291bnQ</global-id>
1016
+ </venmo-account>
1017
+ XML
1018
+ end
974
1019
  end
975
1020
  end
data/lib/braintree.rb CHANGED
@@ -65,6 +65,7 @@ require "braintree/dispute/transaction"
65
65
  require "braintree/dispute/transaction_details"
66
66
  require "braintree/document_upload"
67
67
  require "braintree/document_upload_gateway"
68
+ require "braintree/enriched_customer_data"
68
69
  require "braintree/error_codes"
69
70
  require "braintree/error_result"
70
71
  require "braintree/errors"
@@ -88,6 +89,7 @@ require "braintree/oauth_gateway"
88
89
  require "braintree/oauth_credentials"
89
90
  require "braintree/payment_instrument_type"
90
91
  require "braintree/payment_method"
92
+ require "braintree/payment_method_customer_data_updated_metadata"
91
93
  require "braintree/payment_method_gateway"
92
94
  require "braintree/payment_method_nonce"
93
95
  require "braintree/payment_method_nonce_details"
@@ -155,6 +157,7 @@ require "braintree/dispute_search"
155
157
  require "braintree/validation_error"
156
158
  require "braintree/validation_error_collection"
157
159
  require "braintree/venmo_account"
160
+ require "braintree/venmo_profile_data"
158
161
  require "braintree/version"
159
162
  require "braintree/visa_checkout_card"
160
163
  require "braintree/samsung_pay_card"
@@ -1,5 +1,6 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
2
  require File.expand_path(File.dirname(__FILE__) + "/client_api/spec_helper")
3
+ require "date"
3
4
 
4
5
  describe Braintree::PaymentMethodNonce do
5
6
  let(:config) { Braintree::Configuration.instantiate }
@@ -84,7 +85,7 @@ describe Braintree::PaymentMethodNonce do
84
85
  nonce.details.bin.should == "401288"
85
86
  nonce.details.card_type.should == "Visa"
86
87
  nonce.details.expiration_month.should == "12"
87
- nonce.details.expiration_year.should == "2022"
88
+ nonce.details.expiration_year.should == Date.today.next_year.year.to_s
88
89
  nonce.details.is_network_tokenized?.should be_nil
89
90
  nonce.details.last_two.should == "81"
90
91
  nonce.details.payer_info.should be_nil
@@ -200,7 +200,7 @@ describe Braintree::PaymentMethod do
200
200
  venmo_account.default.should == true
201
201
  venmo_account.token.should == token
202
202
  venmo_account.username.should == "venmojoe"
203
- venmo_account.venmo_user_id.should == "Venmo-Joe-1"
203
+ venmo_account.venmo_user_id.should == "1234567891234567891"
204
204
  venmo_account.image_url.should include(".png")
205
205
  venmo_account.source_description.should == "Venmo Account: venmojoe"
206
206
  venmo_account.customer_id.should == customer.id
@@ -1163,7 +1163,7 @@ describe Braintree::PaymentMethod do
1163
1163
  venmo_account.default.should == true
1164
1164
  venmo_account.image_url.should =~ /venmo/
1165
1165
  venmo_account.username.should == "venmojoe"
1166
- venmo_account.venmo_user_id.should == "Venmo-Joe-1"
1166
+ venmo_account.venmo_user_id.should == "1234567891234567891"
1167
1167
  venmo_account.source_description.should == "Venmo Account: venmojoe"
1168
1168
  venmo_account.customer_id.should == customer.id
1169
1169
  end
@@ -1,4 +1,5 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+ require File.expand_path(File.dirname(__FILE__) + "/client_api/spec_helper")
2
3
 
3
4
  describe Braintree::Plan do
4
5
 
@@ -48,6 +49,87 @@ describe Braintree::Plan do
48
49
  end
49
50
  end
50
51
 
52
+ describe "self.create" do
53
+ let(:attributes) do
54
+ {
55
+ :billing_day_of_month => 12,
56
+ :billing_frequency => 1,
57
+ :currency_iso_code => "USD",
58
+ :description => "description on create",
59
+ :name => "my new plan name",
60
+ :number_of_billing_cycles => 1,
61
+ :price => "9.99",
62
+ :trial_period => false
63
+ }
64
+
65
+ it "is successful with given params" do
66
+ result = Braintree::Plan.create(attributes)
67
+ expect(result.success?).to be_truthy
68
+ expect(result.plan.billing_day_of_month).to eq 12
69
+ expect(result.plan.description).to eq "description on create"
70
+ expect(result.plan.name).to eq "my new plan name"
71
+ expect(result.plan.price).to eq "9.99"
72
+ expect(result.plan.billing_frequency).to eq 1
73
+ end
74
+ end
75
+ end
76
+
77
+ describe "self.find" do
78
+ it "finds a plan" do
79
+ plan = Braintree::Plan.create(
80
+ :billing_day_of_month => 12,
81
+ :billing_frequency => 1,
82
+ :currency_iso_code => "USD",
83
+ :description => "description on create",
84
+ :name => "my new plan name",
85
+ :number_of_billing_cycles => 1,
86
+ :price => "9.99",
87
+ :trial_period => false,
88
+ ).plan
89
+
90
+ found_plan = Braintree::Plan.find(plan.id)
91
+ expect(found_plan.name).to eq plan.name
92
+ end
93
+
94
+ it "raises Braintree::NotFoundError if it cannot find" do
95
+ expect {
96
+ Braintree::Plan.find("noSuchPlan")
97
+ }.to raise_error(Braintree::NotFoundError, 'plan with id "noSuchPlan" not found')
98
+ end
99
+ end
100
+
101
+ describe "self.update!" do
102
+ before(:each) do
103
+ @plan = Braintree::Plan.create(
104
+ :billing_day_of_month => 12,
105
+ :billing_frequency => 1,
106
+ :currency_iso_code => "USD",
107
+ :description => "description on create",
108
+ :name => "my new plan name",
109
+ :number_of_billing_cycles => 1,
110
+ :price => "9.99",
111
+ :trial_period => false,
112
+ ).plan
113
+ end
114
+
115
+ it "returns the updated plan if valid" do
116
+ new_id = rand(36**9).to_s(36)
117
+ plan = Braintree::Plan.update!(@plan.id,
118
+ :name => "updated name",
119
+ :price => 99.88,
120
+ )
121
+
122
+ expect(plan.name).to eq "updated name"
123
+ expect(plan.price).to eq BigDecimal("99.88")
124
+ end
125
+
126
+ it "raises a ValidationsFailed if invalid" do
127
+ expect do
128
+ Braintree::Plan.update!(@plan.id, :number_of_billing_cycles => "number of billing cycles")
129
+ end.to raise_error(Braintree::ValidationsFailed)
130
+ end
131
+ end
132
+
51
133
  def create_plan_for_tests(attributes)
52
134
  config = Braintree::Configuration.gateway.config
53
135
  config.http.post("#{config.base_merchant_path}/plans/create_plan_for_tests", :plan => attributes)
@@ -419,6 +419,17 @@ describe Braintree::Transaction, "search" do
419
419
  collection.maximum_size.should == 0
420
420
  end
421
421
 
422
+ it "searches for settlement_confirmed transaction" do
423
+ transaction_id = "settlement_confirmed_txn"
424
+
425
+ collection = Braintree::Transaction.search do |search|
426
+ search.id.is transaction_id
427
+ end
428
+
429
+ collection.maximum_size.should == 1
430
+ collection.first.id.should == transaction_id
431
+ end
432
+
422
433
  it "finds expired authorizations by status" do
423
434
  collection = Braintree::Transaction.search do |search|
424
435
  search.status.in Braintree::Transaction::Status::AuthorizationExpired
@@ -1947,7 +1947,7 @@ describe Braintree::Transaction do
1947
1947
  venmo_account_details.should be_a(Braintree::Transaction::VenmoAccountDetails)
1948
1948
  venmo_account_details.token.should respond_to(:to_str)
1949
1949
  venmo_account_details.username.should == "venmojoe"
1950
- venmo_account_details.venmo_user_id.should == "Venmo-Joe-1"
1950
+ venmo_account_details.venmo_user_id.should == "1234567891234567891"
1951
1951
  venmo_account_details.image_url.should include(".png")
1952
1952
  venmo_account_details.source_description.should == "Venmo Account: venmojoe"
1953
1953
  end
@@ -6941,6 +6941,39 @@ describe Braintree::Transaction do
6941
6941
  end
6942
6942
  end
6943
6943
 
6944
+ describe "retried flag presence in response" do
6945
+ it "creates a retried transaction" do
6946
+ result = Braintree::Transaction.sale(
6947
+ :amount => Braintree::Test::TransactionAmounts::Decline,
6948
+ :payment_method_token => "network_tokenized_credit_card",
6949
+ )
6950
+ transaction = result.transaction
6951
+ transaction.retried.should == true
6952
+ end
6953
+
6954
+ it "creates a non-retried transaction" do
6955
+ result = Braintree::Transaction.sale(
6956
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
6957
+ :payment_method_token => "network_tokenized_credit_card",
6958
+ )
6959
+ transaction = result.transaction
6960
+ transaction.retried.should == nil
6961
+ end
6962
+
6963
+ it "creates a transaction that is ineligible for retries" do
6964
+ result = Braintree::Transaction.sale(
6965
+ :merchant_account_id => SpecHelper::NonDefaultMerchantAccountId,
6966
+ :credit_card => {
6967
+ :number => Braintree::Test::CreditCardNumbers::Visa,
6968
+ :expiration_date => "05/2009"
6969
+ },
6970
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
6971
+ )
6972
+ transaction = result.transaction
6973
+ transaction.retried.should == nil
6974
+ end
6975
+ end
6976
+
6944
6977
  describe "installments" do
6945
6978
  it "creates a transaction with an installment count" do
6946
6979
  result = Braintree::Transaction.create(
@@ -0,0 +1,32 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ describe Braintree::EnrichedCustomerData do
4
+ describe "self.new" do
5
+ it "is protected" do
6
+ expect do
7
+ Braintree::EnrichedCustomerData.new
8
+ end.to raise_error(NoMethodError, /protected method .new/)
9
+ end
10
+ end
11
+
12
+ describe "self._new" do
13
+ it "initializes the object with the appropriate attributes set" do
14
+
15
+ params = {
16
+ fields_updated: ["username"],
17
+ profile_data: {
18
+ username: "a-username",
19
+ first_name: "a-first-name",
20
+ last_name: "a-last-name",
21
+ phone_number: "a-phone-number",
22
+ email: "a-email",
23
+ },
24
+ }
25
+
26
+ payment_method_customer_data_updated = Braintree::EnrichedCustomerData._new(params)
27
+
28
+ payment_method_customer_data_updated.profile_data.should be_a(Braintree::VenmoProfileData)
29
+ payment_method_customer_data_updated.fields_updated.should eq(["username"])
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,45 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ describe Braintree::PaymentMethodCustomerDataUpdatedMetadata do
4
+ describe "self.new" do
5
+ it "is protected" do
6
+ expect do
7
+ Braintree::PaymentMethodCustomerDataUpdatedMetadata.new
8
+ end.to raise_error(NoMethodError, /protected method .new/)
9
+ end
10
+ end
11
+
12
+ describe "self._new" do
13
+ it "initializes the object with the appropriate attributes set" do
14
+
15
+ params = {
16
+ token: "a-token",
17
+ payment_method: {
18
+ venmo_account: {
19
+ venmo_user_id: "venmo-user-id",
20
+ },
21
+ },
22
+ datetime_updated: "2022-01-01T21:28:37Z",
23
+ enriched_customer_data: {
24
+ fields_updated: ["username"],
25
+ profile_data: {
26
+ username: "a-username",
27
+ first_name: "a-first-name",
28
+ last_name: "a-last-name",
29
+ phone_number: "a-phone-number",
30
+ email: "a-email",
31
+ },
32
+ },
33
+ }
34
+
35
+ payment_method_customer_data_updated = Braintree::PaymentMethodCustomerDataUpdatedMetadata._new(:gateway, params)
36
+
37
+ payment_method_customer_data_updated.token.should eq("a-token")
38
+ payment_method_customer_data_updated.datetime_updated.should eq("2022-01-01T21:28:37Z")
39
+ payment_method_customer_data_updated.payment_method.should be_a(Braintree::VenmoAccount)
40
+ payment_method_customer_data_updated.enriched_customer_data.profile_data.first_name.should eq("a-first-name")
41
+ payment_method_customer_data_updated.enriched_customer_data.profile_data.last_name.should eq("a-last-name")
42
+ payment_method_customer_data_updated.enriched_customer_data.fields_updated.should eq(["username"])
43
+ end
44
+ end
45
+ end
@@ -238,6 +238,14 @@ describe Braintree::Transaction do
238
238
  transaction.network_transaction_id.should == "123456789012345"
239
239
  end
240
240
 
241
+ it "accepts ach_return_code" do
242
+ transaction = Braintree::Transaction._new(
243
+ :gateway,
244
+ :ach_return_code => "R01",
245
+ )
246
+ expect(transaction.ach_return_code).to eq("R01")
247
+ end
248
+
241
249
  it "accepts network_response code and network_response_text" do
242
250
  transaction = Braintree::Transaction._new(
243
251
  :gateway,
@@ -0,0 +1,32 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ describe Braintree::VenmoProfileData do
4
+ describe "self.new" do
5
+ it "is protected" do
6
+ expect do
7
+ Braintree::VenmoProfileData.new
8
+ end.to raise_error(NoMethodError, /protected method .new/)
9
+ end
10
+ end
11
+
12
+ describe "self._new" do
13
+ it "initializes the object with the appropriate attributes set" do
14
+
15
+ params = {
16
+ username: "a-username",
17
+ first_name: "a-first-name",
18
+ last_name: "a-last-name",
19
+ phone_number: "12312312343",
20
+ email: "a-email",
21
+ }
22
+
23
+ payment_method_customer_data_updated = Braintree::VenmoProfileData._new(params)
24
+
25
+ payment_method_customer_data_updated.username.should eq("a-username")
26
+ payment_method_customer_data_updated.first_name.should eq("a-first-name")
27
+ payment_method_customer_data_updated.last_name.should eq("a-last-name")
28
+ payment_method_customer_data_updated.phone_number.should eq("12312312343")
29
+ payment_method_customer_data_updated.email.should eq("a-email")
30
+ end
31
+ end
32
+ end
@@ -317,6 +317,24 @@ describe Braintree::WebhookNotification do
317
317
  end
318
318
  end
319
319
 
320
+ context "transaction review" do
321
+ it " builds a sample notification for a transaction reviewed webhook" do
322
+ sample_notification = Braintree::WebhookTesting.sample_notification(
323
+ Braintree::WebhookNotification::Kind::TransactionReviewed,
324
+ "my_id",
325
+ )
326
+
327
+ notification = Braintree::WebhookNotification.parse(sample_notification[:bt_signature], sample_notification[:bt_payload])
328
+
329
+ expect(notification.kind).to eq(Braintree::WebhookNotification::Kind::TransactionReviewed)
330
+ expect(notification.transaction_review.transaction_id).to eq("my_id")
331
+ expect(notification.transaction_review.decision).to eq("decision")
332
+ expect(notification.transaction_review.reviewer_email).to eq("hey@girl.com")
333
+ expect(notification.transaction_review.reviewer_note).to eq("i reviewed this")
334
+ expect(notification.transaction_review.reviewed_time).to_not be_nil
335
+ end
336
+ end
337
+
320
338
  context "us bank account transactions" do
321
339
  it "builds a sample notification for a settlement webhook" do
322
340
  sample_notification = Braintree::WebhookTesting.sample_notification(
@@ -717,6 +735,32 @@ describe Braintree::WebhookNotification do
717
735
  end
718
736
  end
719
737
 
738
+ context "payment_method_customer_data_updated" do
739
+ it "builds a sample notification for a payment_method_customer_data_updated webhook" do
740
+ sample_notification = Braintree::WebhookTesting.sample_notification(
741
+ Braintree::WebhookNotification::Kind::PaymentMethodCustomerDataUpdated,
742
+ "my_id",
743
+ )
744
+ notification = Braintree::WebhookNotification.parse(sample_notification[:bt_signature], sample_notification[:bt_payload])
745
+ notification.kind.should == Braintree::WebhookNotification::Kind::PaymentMethodCustomerDataUpdated
746
+
747
+ payment_method_customer_data_updated = notification.payment_method_customer_data_updated_metadata
748
+
749
+ payment_method_customer_data_updated.token.should eq("TOKEN-12345")
750
+ payment_method_customer_data_updated.datetime_updated.should eq("2022-01-01T21:28:37Z")
751
+
752
+ enriched_customer_data = payment_method_customer_data_updated.enriched_customer_data
753
+ enriched_customer_data.fields_updated.should eq(["username"])
754
+
755
+ profile_data = enriched_customer_data.profile_data
756
+ profile_data.first_name.should eq("John")
757
+ profile_data.last_name.should eq("Doe")
758
+ profile_data.username.should eq("venmo_username")
759
+ profile_data.phone_number.should eq("1231231234")
760
+ profile_data.email.should eq("john.doe@paypal.com")
761
+ end
762
+ end
763
+
720
764
  describe "parse" do
721
765
  it "raises InvalidSignature error when the signature is nil" do
722
766
  expect do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: braintree
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.4.0
4
+ version: 4.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Braintree
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-05 00:00:00.000000000 Z
11
+ date: 2022-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: builder
@@ -92,6 +92,7 @@ files:
92
92
  - lib/braintree/dispute_search.rb
93
93
  - lib/braintree/document_upload.rb
94
94
  - lib/braintree/document_upload_gateway.rb
95
+ - lib/braintree/enriched_customer_data.rb
95
96
  - lib/braintree/error_codes.rb
96
97
  - lib/braintree/error_result.rb
97
98
  - lib/braintree/errors.rb
@@ -122,6 +123,7 @@ files:
122
123
  - lib/braintree/paginated_result.rb
123
124
  - lib/braintree/payment_instrument_type.rb
124
125
  - lib/braintree/payment_method.rb
126
+ - lib/braintree/payment_method_customer_data_updated_metadata.rb
125
127
  - lib/braintree/payment_method_gateway.rb
126
128
  - lib/braintree/payment_method_nonce.rb
127
129
  - lib/braintree/payment_method_nonce_details.rb
@@ -176,6 +178,7 @@ files:
176
178
  - lib/braintree/transaction_gateway.rb
177
179
  - lib/braintree/transaction_line_item.rb
178
180
  - lib/braintree/transaction_line_item_gateway.rb
181
+ - lib/braintree/transaction_review.rb
179
182
  - lib/braintree/transaction_search.rb
180
183
  - lib/braintree/unknown_payment_method.rb
181
184
  - lib/braintree/us_bank_account.rb
@@ -187,6 +190,7 @@ files:
187
190
  - lib/braintree/validation_error.rb
188
191
  - lib/braintree/validation_error_collection.rb
189
192
  - lib/braintree/venmo_account.rb
193
+ - lib/braintree/venmo_profile_data.rb
190
194
  - lib/braintree/version.rb
191
195
  - lib/braintree/visa_checkout_card.rb
192
196
  - lib/braintree/webhook_notification.rb
@@ -268,6 +272,7 @@ files:
268
272
  - spec/unit/braintree/dispute_search_spec.rb
269
273
  - spec/unit/braintree/dispute_spec.rb
270
274
  - spec/unit/braintree/document_upload_spec.rb
275
+ - spec/unit/braintree/enriched_customer_data_spec.rb
271
276
  - spec/unit/braintree/error_result_spec.rb
272
277
  - spec/unit/braintree/errors_spec.rb
273
278
  - spec/unit/braintree/http_spec.rb
@@ -276,6 +281,7 @@ files:
276
281
  - spec/unit/braintree/local_payment_funded_spec.rb
277
282
  - spec/unit/braintree/merchant_account_spec.rb
278
283
  - spec/unit/braintree/modification_spec.rb
284
+ - spec/unit/braintree/payment_method_customer_data_updated_metadata_spec.rb
279
285
  - spec/unit/braintree/payment_method_nonce_details_payer_info_spec.rb
280
286
  - spec/unit/braintree/payment_method_nonce_details_spec.rb
281
287
  - spec/unit/braintree/payment_method_nonce_spec.rb
@@ -303,6 +309,7 @@ files:
303
309
  - spec/unit/braintree/util_spec.rb
304
310
  - spec/unit/braintree/validation_error_collection_spec.rb
305
311
  - spec/unit/braintree/validation_error_spec.rb
312
+ - spec/unit/braintree/venmo_profile_data_spec.rb
306
313
  - spec/unit/braintree/webhook_notification_spec.rb
307
314
  - spec/unit/braintree/xml/libxml_spec.rb
308
315
  - spec/unit/braintree/xml/parser_spec.rb
@@ -317,7 +324,7 @@ metadata:
317
324
  bug_tracker_uri: https://github.com/braintree/braintree_ruby/issues
318
325
  changelog_uri: https://github.com/braintree/braintree_ruby/blob/master/CHANGELOG.md
319
326
  source_code_uri: https://github.com/braintree/braintree_ruby
320
- documentation_uri: https://developers.braintreepayments.com/
327
+ documentation_uri: https://developer.paypal.com/braintree/docs
321
328
  post_install_message:
322
329
  rdoc_options: []
323
330
  require_paths:
@@ -333,7 +340,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
333
340
  - !ruby/object:Gem::Version
334
341
  version: '0'
335
342
  requirements: []
336
- rubygems_version: 3.2.25
343
+ rubygems_version: 3.3.10
337
344
  signing_key:
338
345
  specification_version: 4
339
346
  summary: Braintree Ruby Server SDK