braintree 2.73.0 → 2.74.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -35,9 +35,22 @@ module Braintree
35
35
 
36
36
  IdealPaymentComplete = "ideal_payment_complete"
37
37
  IdealPaymentFailed = "ideal_payment_failed"
38
+
39
+ ConnectedMerchantStatusTransitioned = "connected_merchant_status_transitioned"
40
+ ConnectedMerchantPayPalStatusChanged = "connected_merchant_paypal_status_changed"
38
41
  end
39
42
 
40
- attr_reader :subscription, :kind, :timestamp, :transaction, :partner_merchant, :disbursement, :dispute, :account_updater_daily_report, :ideal_payment
43
+ attr_reader :subscription
44
+ attr_reader :kind
45
+ attr_reader :timestamp
46
+ attr_reader :transaction
47
+ attr_reader :partner_merchant
48
+ attr_reader :disbursement
49
+ attr_reader :dispute
50
+ attr_reader :account_updater_daily_report
51
+ attr_reader :ideal_payment
52
+ attr_reader :connected_merchant_status_transitioned
53
+ attr_reader :connected_merchant_paypal_status_changed
41
54
 
42
55
  def self.parse(signature, payload)
43
56
  Configuration.gateway.webhook_notification.parse(signature, payload)
@@ -59,6 +72,8 @@ module Braintree
59
72
  @dispute = Dispute._new(@subject[:dispute]) if @subject.has_key?(:dispute)
60
73
  @account_updater_daily_report = AccountUpdaterDailyReport._new(@subject[:account_updater_daily_report]) if @subject.has_key?(:account_updater_daily_report)
61
74
  @ideal_payment = Braintree::IdealPayment._new(gateway, @subject[:ideal_payment]) if @subject.has_key?(:ideal_payment)
75
+ @connected_merchant_status_transitioned = ConnectedMerchantStatusTransitioned._new(@subject[:connected_merchant_status_transitioned]) if @subject.has_key?(:connected_merchant_status_transitioned)
76
+ @connected_merchant_paypal_status_changed = ConnectedMerchantPayPalStatusChanged._new(@subject[:connected_merchant_paypal_status_changed]) if @subject.has_key?(:connected_merchant_paypal_status_changed)
62
77
  end
63
78
 
64
79
  def merchant_account
@@ -59,6 +59,10 @@ module Braintree
59
59
  _subscription_charged_successfully(id)
60
60
  when Braintree::WebhookNotification::Kind::AccountUpdaterDailyReport
61
61
  _account_updater_daily_report_sample_xml(id)
62
+ when Braintree::WebhookNotification::Kind::ConnectedMerchantStatusTransitioned
63
+ _auth_status_transitioned_sample_xml(id)
64
+ when Braintree::WebhookNotification::Kind::ConnectedMerchantPayPalStatusChanged
65
+ _auth_paypal_status_changed_sample_xml(id)
62
66
  when Braintree::WebhookNotification::Kind::IdealPaymentComplete
63
67
  _ideal_payment_complete_sample_xml(id)
64
68
  when Braintree::WebhookNotification::Kind::IdealPaymentFailed
@@ -360,6 +364,26 @@ module Braintree
360
364
  XML
361
365
  end
362
366
 
367
+ def _auth_status_transitioned_sample_xml(id)
368
+ <<-XML
369
+ <connected-merchant-status-transitioned>
370
+ <merchant-public-id>#{id}</merchant-public-id>
371
+ <status>new_status</status>
372
+ <oauth-application-client-id>oauth_application_client_id</oauth-application-client-id>
373
+ </connected-merchant-status-transitioned>
374
+ XML
375
+ end
376
+
377
+ def _auth_paypal_status_changed_sample_xml(id)
378
+ <<-XML
379
+ <connected-merchant-paypal-status-changed>
380
+ <oauth-application-client-id>oauth_application_client_id</oauth-application-client-id>
381
+ <merchant-public-id>#{id}</merchant-public-id>
382
+ <action>link</action>
383
+ </connected-merchant-paypal-status-changed>
384
+ XML
385
+ end
386
+
363
387
  def _ideal_payment_complete_sample_xml(id)
364
388
 
365
389
  <<-XML
@@ -1 +1 @@
1
- 12403
1
+ 15408
@@ -84,8 +84,13 @@ def generate_valid_us_bank_account_nonce()
84
84
  end
85
85
 
86
86
  def generate_valid_ideal_payment_nonce(amount = Braintree::Test::TransactionAmounts::Authorize)
87
- raw_client_token = Braintree::ClientToken.generate
87
+ raw_client_token = Braintree::ClientToken.generate(:merchant_account_id => "ideal_merchant_account")
88
88
  client_token = decode_client_token(raw_client_token)
89
+ client = ClientApiHttp.new(
90
+ Braintree::Configuration.instantiate,
91
+ :authorization_fingerprint => client_token["authorizationFingerprint"],
92
+ )
93
+ config = JSON.parse(client.get_configuration.body)
89
94
 
90
95
  token = client_token["braintree_api"]["access_token"]
91
96
  url = client_token["braintree_api"]["url"] + "/ideal-payments"
@@ -95,6 +100,7 @@ def generate_valid_ideal_payment_nonce(amount = Braintree::Test::TransactionAmou
95
100
  :amount => amount,
96
101
  :currency => "EUR",
97
102
  :redirect_url => "https://braintree-api.com",
103
+ :route_id => config["ideal"]["routeId"]
98
104
  }
99
105
 
100
106
  json = _cosmos_post(token, url, payload)
@@ -183,6 +189,15 @@ class ClientApiHttp
183
189
  end
184
190
  end
185
191
 
192
+ def get_configuration
193
+ encoded_fingerprint = Braintree::Util.url_encode(@options[:authorization_fingerprint])
194
+ url = "/merchants/#{@config.merchant_id}/client_api/v1/configuration"
195
+ url += "?authorizationFingerprint=#{encoded_fingerprint}"
196
+ url += "&configVersion=3"
197
+
198
+ get(url)
199
+ end
200
+
186
201
  def get_payment_methods
187
202
  encoded_fingerprint = Braintree::Util.url_encode(@options[:authorization_fingerprint])
188
203
  url = "/merchants/#{@config.merchant_id}/client_api/v1/payment_methods?"
@@ -1473,6 +1473,64 @@ describe Braintree::Customer do
1473
1473
  end
1474
1474
  end
1475
1475
 
1476
+ context "limited use" do
1477
+ it "creates a customer with payment_method_nonce and options->paypal->payee_email" do
1478
+ paypal_account_token = "PAYPAL_ACCOUNT_TOKEN_#{rand(36**3).to_s(36)}"
1479
+ nonce = nonce_for_paypal_account(
1480
+ :consent_code => "PAYPAL_CONSENT_CODE",
1481
+ :token => paypal_account_token,
1482
+ :options => {
1483
+ :make_default => true
1484
+ }
1485
+ )
1486
+
1487
+ result = Braintree::Customer.create(
1488
+ :payment_method_nonce => nonce,
1489
+ :options => {
1490
+ :paypal => {
1491
+ :payee_email => "payee@example.com",
1492
+ },
1493
+ },
1494
+ )
1495
+
1496
+ result.should be_success
1497
+ end
1498
+
1499
+ it "updates a customer with payment_method_nonce and options->paypal->payee_email" do
1500
+ customer = Braintree::Customer.create!(
1501
+ :credit_card => {
1502
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1503
+ :expiration_date => "12/2015",
1504
+ :options => {
1505
+ :make_default => true
1506
+ }
1507
+ }
1508
+ )
1509
+
1510
+ paypal_account_token = "PAYPAL_ACCOUNT_TOKEN_#{rand(36**3).to_s(36)}"
1511
+ nonce = nonce_for_paypal_account(
1512
+ :consent_code => "PAYPAL_CONSENT_CODE",
1513
+ :token => paypal_account_token,
1514
+ :options => {
1515
+ :make_default => true
1516
+ }
1517
+ )
1518
+
1519
+ result = Braintree::Customer.update(
1520
+ customer.id,
1521
+ :payment_method_nonce => nonce,
1522
+ :options => {
1523
+ :paypal => {
1524
+ :payee_email => "payee@example.com",
1525
+ },
1526
+ },
1527
+ )
1528
+
1529
+ result.should be_success
1530
+ result.customer.default_payment_method.token.should == paypal_account_token
1531
+ end
1532
+ end
1533
+
1476
1534
  context "onetime" do
1477
1535
  it "does not create a customer with a onetime paypal account" do
1478
1536
  result = Braintree::Customer.create(
@@ -0,0 +1,97 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+ require File.expand_path(File.dirname(__FILE__) + "/client_api/spec_helper")
3
+
4
+ describe Braintree::MasterpassCard do
5
+ it "can create from a payment method nonce" do
6
+ customer = Braintree::Customer.create!
7
+
8
+ result = Braintree::PaymentMethod.create(
9
+ :payment_method_nonce => Braintree::Test::Nonce::MasterpassDiscover,
10
+ :customer_id => customer.id
11
+ )
12
+ result.should be_success
13
+
14
+ masterpass_card = result.payment_method
15
+ masterpass_card.should be_a(Braintree::MasterpassCard)
16
+ masterpass_card.billing_address.should_not be_nil
17
+ masterpass_card.bin.should_not be_nil
18
+ masterpass_card.card_type.should_not be_nil
19
+ masterpass_card.cardholder_name.should_not be_nil
20
+ masterpass_card.commercial.should_not be_nil
21
+ masterpass_card.country_of_issuance.should_not be_nil
22
+ masterpass_card.created_at.should_not be_nil
23
+ masterpass_card.customer_id.should_not be_nil
24
+ masterpass_card.customer_location.should_not be_nil
25
+ masterpass_card.debit.should_not be_nil
26
+ masterpass_card.default?.should_not be_nil
27
+ masterpass_card.durbin_regulated.should_not be_nil
28
+ masterpass_card.expiration_date.should_not be_nil
29
+ masterpass_card.expiration_month.should_not be_nil
30
+ masterpass_card.expiration_year.should_not be_nil
31
+ masterpass_card.expired?.should_not be_nil
32
+ masterpass_card.healthcare.should_not be_nil
33
+ masterpass_card.image_url.should_not be_nil
34
+ masterpass_card.issuing_bank.should_not be_nil
35
+ masterpass_card.last_4.should_not be_nil
36
+ masterpass_card.payroll.should_not be_nil
37
+ masterpass_card.prepaid.should_not be_nil
38
+ masterpass_card.product_id.should_not be_nil
39
+ masterpass_card.subscriptions.should_not be_nil
40
+ masterpass_card.token.should_not be_nil
41
+ masterpass_card.unique_number_identifier.should_not be_nil
42
+ masterpass_card.updated_at.should_not be_nil
43
+
44
+ customer = Braintree::Customer.find(customer.id)
45
+ customer.masterpass_cards.size.should == 1
46
+ customer.masterpass_cards.first.should == masterpass_card
47
+ end
48
+
49
+ it "can search for transactions" do
50
+ transaction_create_result = Braintree::Transaction.sale(
51
+ :payment_method_nonce => Braintree::Test::Nonce::MasterpassDiscover,
52
+ :amount => '47.00',
53
+ )
54
+ transaction_create_result.should be_success
55
+ transaction_id = transaction_create_result.transaction.id
56
+
57
+ search_results = Braintree::Transaction.search do |search|
58
+ search.id.is transaction_id
59
+ search.payment_instrument_type.is Braintree::PaymentInstrumentType::MasterpassCard
60
+ end
61
+ search_results.first.id.should == transaction_id
62
+ end
63
+
64
+ it "can create transaction from nonce and vault" do
65
+ customer = Braintree::Customer.create!
66
+
67
+ result = Braintree::Transaction.sale(
68
+ :payment_method_nonce => Braintree::Test::Nonce::MasterpassDiscover,
69
+ :customer_id => customer.id,
70
+ :amount => '47.00',
71
+ :options => { :store_in_vault => true },
72
+ )
73
+ result.should be_success
74
+
75
+ masterpass_card_details = result.transaction.masterpass_card_details
76
+ masterpass_card_details.bin.should_not be_nil
77
+ masterpass_card_details.card_type.should_not be_nil
78
+ masterpass_card_details.cardholder_name.should_not be_nil
79
+ masterpass_card_details.commercial.should_not be_nil
80
+ masterpass_card_details.country_of_issuance.should_not be_nil
81
+ masterpass_card_details.customer_location.should_not be_nil
82
+ masterpass_card_details.debit.should_not be_nil
83
+ masterpass_card_details.durbin_regulated.should_not be_nil
84
+ masterpass_card_details.expiration_date.should_not be_nil
85
+ masterpass_card_details.expiration_month.should_not be_nil
86
+ masterpass_card_details.expiration_year.should_not be_nil
87
+ masterpass_card_details.healthcare.should_not be_nil
88
+ masterpass_card_details.image_url.should_not be_nil
89
+ masterpass_card_details.issuing_bank.should_not be_nil
90
+ masterpass_card_details.last_4.should_not be_nil
91
+ masterpass_card_details.payroll.should_not be_nil
92
+ masterpass_card_details.prepaid.should_not be_nil
93
+ masterpass_card_details.product_id.should_not be_nil
94
+ masterpass_card_details.token.should_not be_nil
95
+ end
96
+ end
97
+
@@ -246,7 +246,7 @@ describe Braintree::PaymentMethod do
246
246
  it "respects verify_card and verification_merchant_account_id when included outside of the nonce" do
247
247
  nonce = nonce_for_new_payment_method(
248
248
  :credit_card => {
249
- :number => "4000111111111115",
249
+ :number => Braintree::Test::CreditCardNumbers::FailsSandboxVerification::Visa,
250
250
  :expiration_month => "11",
251
251
  :expiration_year => "2099",
252
252
  }
@@ -271,7 +271,7 @@ describe Braintree::PaymentMethod do
271
271
  it "respects verification amount when included outside of the nonce" do
272
272
  nonce = nonce_for_new_payment_method(
273
273
  :credit_card => {
274
- :number => "4000111111111115",
274
+ :number => Braintree::Test::CreditCardNumbers::FailsSandboxVerification::Visa,
275
275
  :expiration_month => "11",
276
276
  :expiration_year => "2099",
277
277
  }
@@ -290,6 +290,7 @@ describe Braintree::PaymentMethod do
290
290
  result.credit_card_verification.status.should == Braintree::Transaction::Status::ProcessorDeclined
291
291
  result.credit_card_verification.processor_response_code.should == "2000"
292
292
  result.credit_card_verification.processor_response_text.should == "Do Not Honor"
293
+ result.credit_card_verification.amount.should == BigDecimal.new("100.00")
293
294
  end
294
295
 
295
296
  it "respects fail_on_duplicate_payment_method when included outside of the nonce" do
@@ -534,6 +535,32 @@ describe Braintree::PaymentMethod do
534
535
  found_paypal_account.should_not be_nil
535
536
  end
536
537
 
538
+ it "creates a limited use payment method from a paypal account nonce for a paypal intent==order payment" do
539
+ nonce = nonce_for_paypal_account(
540
+ :intent => "order",
541
+ :payment_token => "fake-payment-token",
542
+ :payer_id => "fake-payer-id",
543
+ )
544
+ customer = Braintree::Customer.create.customer
545
+ result = Braintree::PaymentMethod.create(
546
+ :payment_method_nonce => nonce,
547
+ :customer_id => customer.id,
548
+ :options => {
549
+ :paypal => {
550
+ :payee_email => "payee@example.com",
551
+ },
552
+ },
553
+ )
554
+
555
+ result.should be_success
556
+ result.payment_method.should be_a(Braintree::PayPalAccount)
557
+ result.payment_method.image_url.should_not be_nil
558
+ token = result.payment_method.token
559
+
560
+ found_paypal_account = Braintree::PayPalAccount.find(token)
561
+ found_paypal_account.should_not be_nil
562
+ end
563
+
537
564
  it "does not create a payment method from an unvalidated onetime paypal account nonce" do
538
565
  customer = Braintree::Customer.create.customer
539
566
  nonce = nonce_for_paypal_account(:access_token => "PAYPAL_ACCESS_TOKEN")
@@ -1101,6 +1128,7 @@ describe Braintree::PaymentMethod do
1101
1128
  update_result.success?.should == false
1102
1129
  update_result.credit_card_verification.status.should == Braintree::Transaction::Status::ProcessorDeclined
1103
1130
  update_result.credit_card_verification.gateway_rejection_reason.should be_nil
1131
+ update_result.credit_card_verification.amount.should == BigDecimal("2.34")
1104
1132
  end
1105
1133
 
1106
1134
  it "can update the billing address" do
@@ -0,0 +1,110 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+ require File.expand_path(File.dirname(__FILE__) + "/client_api/spec_helper")
3
+
4
+ describe Braintree::VisaCheckoutCard do
5
+ it "can create from payment method nonce" do
6
+ customer = Braintree::Customer.create!
7
+
8
+ result = Braintree::PaymentMethod.create(
9
+ :payment_method_nonce => Braintree::Test::Nonce::VisaCheckoutDiscover,
10
+ :customer_id => customer.id
11
+ )
12
+ result.should be_success
13
+
14
+ visa_checkout_card = result.payment_method
15
+ visa_checkout_card.should be_a(Braintree::VisaCheckoutCard)
16
+ visa_checkout_card.call_id.should == "abc123"
17
+ visa_checkout_card.billing_address.should_not be_nil
18
+ visa_checkout_card.bin.should_not be_nil
19
+ visa_checkout_card.card_type.should_not be_nil
20
+ visa_checkout_card.cardholder_name.should_not be_nil
21
+ visa_checkout_card.commercial.should_not be_nil
22
+ visa_checkout_card.country_of_issuance.should_not be_nil
23
+ visa_checkout_card.created_at.should_not be_nil
24
+ visa_checkout_card.customer_id.should_not be_nil
25
+ visa_checkout_card.customer_location.should_not be_nil
26
+ visa_checkout_card.debit.should_not be_nil
27
+ visa_checkout_card.default?.should_not be_nil
28
+ visa_checkout_card.durbin_regulated.should_not be_nil
29
+ visa_checkout_card.expiration_date.should_not be_nil
30
+ visa_checkout_card.expiration_month.should_not be_nil
31
+ visa_checkout_card.expiration_year.should_not be_nil
32
+ visa_checkout_card.expired?.should_not be_nil
33
+ visa_checkout_card.healthcare.should_not be_nil
34
+ visa_checkout_card.image_url.should_not be_nil
35
+ visa_checkout_card.issuing_bank.should_not be_nil
36
+ visa_checkout_card.last_4.should_not be_nil
37
+ visa_checkout_card.payroll.should_not be_nil
38
+ visa_checkout_card.prepaid.should_not be_nil
39
+ visa_checkout_card.product_id.should_not be_nil
40
+ visa_checkout_card.subscriptions.should_not be_nil
41
+ visa_checkout_card.token.should_not be_nil
42
+ visa_checkout_card.unique_number_identifier.should_not be_nil
43
+ visa_checkout_card.updated_at.should_not be_nil
44
+
45
+ customer = Braintree::Customer.find(customer.id)
46
+ customer.visa_checkout_cards.size.should == 1
47
+ customer.visa_checkout_cards.first.should == visa_checkout_card
48
+ end
49
+
50
+ it "can create with verification" do
51
+ customer = Braintree::Customer.create!
52
+
53
+ result = Braintree::PaymentMethod.create(
54
+ :payment_method_nonce => Braintree::Test::Nonce::VisaCheckoutDiscover,
55
+ :customer_id => customer.id,
56
+ :options => { :verify_card => true }
57
+ )
58
+ result.should be_success
59
+ result.payment_method.verification.status.should == Braintree::CreditCardVerification::Status::Verified
60
+ end
61
+
62
+ it "can search for transactions" do
63
+ transaction_create_result = Braintree::Transaction.sale(
64
+ :payment_method_nonce => Braintree::Test::Nonce::VisaCheckoutDiscover,
65
+ :amount => '47.00',
66
+ )
67
+ transaction_create_result.should be_success
68
+ transaction_id = transaction_create_result.transaction.id
69
+
70
+ search_results = Braintree::Transaction.search do |search|
71
+ search.id.is transaction_id
72
+ search.payment_instrument_type.is Braintree::PaymentInstrumentType::VisaCheckoutCard
73
+ end
74
+ search_results.first.id.should == transaction_id
75
+ end
76
+
77
+ it "can create transaction from nonce and vault" do
78
+ customer = Braintree::Customer.create!
79
+
80
+ result = Braintree::Transaction.sale(
81
+ :payment_method_nonce => Braintree::Test::Nonce::VisaCheckoutDiscover,
82
+ :customer_id => customer.id,
83
+ :amount => '47.00',
84
+ :options => { :store_in_vault => true },
85
+ )
86
+ result.should be_success
87
+
88
+ visa_checkout_card_details = result.transaction.visa_checkout_card_details
89
+ visa_checkout_card_details.call_id.should == "abc123"
90
+ visa_checkout_card_details.bin.should_not be_nil
91
+ visa_checkout_card_details.card_type.should_not be_nil
92
+ visa_checkout_card_details.cardholder_name.should_not be_nil
93
+ visa_checkout_card_details.commercial.should_not be_nil
94
+ visa_checkout_card_details.country_of_issuance.should_not be_nil
95
+ visa_checkout_card_details.customer_location.should_not be_nil
96
+ visa_checkout_card_details.debit.should_not be_nil
97
+ visa_checkout_card_details.durbin_regulated.should_not be_nil
98
+ visa_checkout_card_details.expiration_date.should_not be_nil
99
+ visa_checkout_card_details.expiration_month.should_not be_nil
100
+ visa_checkout_card_details.expiration_year.should_not be_nil
101
+ visa_checkout_card_details.healthcare.should_not be_nil
102
+ visa_checkout_card_details.image_url.should_not be_nil
103
+ visa_checkout_card_details.issuing_bank.should_not be_nil
104
+ visa_checkout_card_details.last_4.should_not be_nil
105
+ visa_checkout_card_details.payroll.should_not be_nil
106
+ visa_checkout_card_details.prepaid.should_not be_nil
107
+ visa_checkout_card_details.product_id.should_not be_nil
108
+ visa_checkout_card_details.token.should_not be_nil
109
+ end
110
+ end