Skip to content

Commit

Permalink
4.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
braintreeps committed Aug 5, 2021
1 parent 375df2b commit 7d4182b
Show file tree
Hide file tree
Showing 12 changed files with 182 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 4.4.0
* Sanitize encrypted_card_data logs
* Add `LocalPaymentExpired` and `LocalPaymentFunded` webhook notification support

## 4.3.0
* Add a log message to the `ArgumentError` at `TransactionGateway.find`
* Add `exchange_rate_quote_id` to `Transaction.create`
Expand Down
2 changes: 2 additions & 0 deletions lib/braintree.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
require "braintree/google_pay_card"
require "braintree/local_payment_completed"
require "braintree/local_payment_reversed"
require "braintree/local_payment_expired"
require "braintree/local_payment_funded"
require "braintree/transaction/local_payment_details"
require "braintree/merchant"
require "braintree/merchant_gateway"
Expand Down
1 change: 1 addition & 0 deletions lib/braintree/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ def _format_and_sanitize_body_for_log(input_xml)
formatted_xml = input_xml.gsub(/^/, "[Braintree] ")
formatted_xml = formatted_xml.gsub(/<number>(.{6}).+?(.{4})<\/number>/m, '<number>\1******\2</number>')
formatted_xml = formatted_xml.gsub(/<cvv>.+?<\/cvv>/m, "<cvv>***</cvv>")
formatted_xml = formatted_xml.gsub(/<encrypted-card-data>.+?<\/encrypted-card-data>/m, "<encrypted-card-data>***</encrypted-card-data>")
formatted_xml
end

Expand Down
21 changes: 21 additions & 0 deletions lib/braintree/local_payment_expired.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module Braintree
class LocalPaymentExpired
include BaseModule

attr_reader :payment_id
attr_reader :payment_context_id

def initialize(attributes) # :nodoc:
set_instance_variables_from_hash(attributes)
end

class << self
protected :new
end

def self._new(*args) # :nodoc:
self.new(*args)
end
end
end

22 changes: 22 additions & 0 deletions lib/braintree/local_payment_funded.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module Braintree
class LocalPaymentFunded
include BaseModule

attr_reader :payment_id
attr_reader :payment_context_id
attr_reader :transaction

def initialize(attributes) # :nodoc:
set_instance_variables_from_hash(attributes)
@transaction = Transaction._new(Configuration.gateway, transaction)
end

class << self
protected :new
end

def self._new(*args) # :nodoc:
self.new(*args)
end
end
end
2 changes: 1 addition & 1 deletion lib/braintree/version.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Braintree
module Version
Major = 4
Minor = 3
Minor = 4
Tiny = 0

String = "#{Major}.#{Minor}.#{Tiny}"
Expand Down
6 changes: 6 additions & 0 deletions lib/braintree/webhook_notification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ module Kind
GrantedPaymentMethodRevoked = "granted_payment_method_revoked"

LocalPaymentCompleted = "local_payment_completed"
LocalPaymentExpired = "local_payment_expired"
LocalPaymentFunded = "local_payment_funded"
LocalPaymentReversed = "local_payment_reversed"

OAuthAccessRevoked = "oauth_access_revoked"
Expand Down Expand Up @@ -65,6 +67,8 @@ module Kind
attr_reader :revoked_payment_method_metadata
attr_reader :kind
attr_reader :local_payment_completed
attr_reader :local_payment_expired
attr_reader :local_payment_funded
attr_reader :local_payment_reversed
attr_reader :oauth_access_revocation
attr_reader :partner_merchant
Expand Down Expand Up @@ -98,6 +102,8 @@ def initialize(gateway, attributes) # :nodoc:
@granted_payment_instrument_update = GrantedPaymentInstrumentUpdate._new(@subject[:granted_payment_instrument_update]) if @subject.has_key?(:granted_payment_instrument_update)
@revoked_payment_method_metadata = RevokedPaymentMethodMetadata._new(gateway, @subject) if [Kind::GrantedPaymentInstrumentRevoked, Kind::PaymentMethodRevokedByCustomer, Kind::GrantedPaymentMethodRevoked].include?(@kind)
@local_payment_completed = LocalPaymentCompleted._new(@subject[:local_payment]) if @subject.has_key?(:local_payment) && Kind::LocalPaymentCompleted == @kind
@local_payment_expired = LocalPaymentExpired._new(@subject[:local_payment_expired]) if @subject.has_key?(:local_payment_expired) && Kind::LocalPaymentExpired == @kind
@local_payment_funded = LocalPaymentFunded._new(@subject[:local_payment_funded]) if @subject.has_key?(:local_payment_funded) && Kind::LocalPaymentFunded == @kind
@local_payment_reversed = LocalPaymentReversed._new(@subject[:local_payment_reversed]) if @subject.has_key?(:local_payment_reversed) && Kind::LocalPaymentReversed == @kind
end

Expand Down
33 changes: 31 additions & 2 deletions lib/braintree/webhook_testing_gateway.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,12 @@ def _subject_sample_xml(kind, id)
_payment_method_revoked_by_customer_sample_xml(id)
when Braintree::WebhookNotification::Kind::LocalPaymentCompleted
_local_payment_completed_sample_xml(id)
when Braintree::WebhookNotification::Kind::LocalPaymentExpired
_local_payment_expired_sample_xml
when Braintree::WebhookNotification::Kind::LocalPaymentFunded
_local_payment_funded_sample_xml(id)
when Braintree::WebhookNotification::Kind::LocalPaymentReversed
_local_payment_reversed_sample_xml(id)
_local_payment_reversed_sample_xml
else
_subscription_sample_xml(id)
end
Expand Down Expand Up @@ -935,10 +939,35 @@ def _local_payment_completed_sample_xml(id)
XML
end

def _local_payment_reversed_sample_xml(id)
def _local_payment_expired_sample_xml
<<-XML
<local-payment-expired>
<payment-id>PAY-XYZ123</payment-id>
<payment-context-id>cG5b=</payment-context-id>
</local-payment-expired>
XML
end

def _local_payment_funded_sample_xml(id)
<<-XML
<local-payment-funded>
<payment-id>PAY-XYZ123</payment-id>
<payment-context-id>cG5b=</payment-context-id>
<transaction>
<id>#{id}</id>
<status>settled</status>
<amount>49.99</amount>
<order-id>order4567</order-id>
</transaction>
</local-payment-funded>
XML
end

def _local_payment_reversed_sample_xml
<<-XML
<local-payment-reversed>
<payment-id>PAY-XYZ123</payment-id>
<payment-context-id>cG5b=</payment-context-id>
</local-payment-reversed>
XML
end
Expand Down
2 changes: 2 additions & 0 deletions spec/unit/braintree/http_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<last-name>Doe</last-name>
<number>1234560000001234</number>
<cvv>123</cvv>
<encrypted-card-data>8F34DFB312DC79C24FD5320622F3E11682D79E6B0C0FD881</encrypted-card-data>
</customer>
END

Expand All @@ -34,6 +35,7 @@
[Braintree] <last-name>Doe</last-name>
[Braintree] <number>123456******1234</number>
[Braintree] <cvv>***</cvv>
[Braintree] <encrypted-card-data>***</encrypted-card-data>
[Braintree] </customer>
END
Braintree::Http.new(:config)._format_and_sanitize_body_for_log(input_xml).should == expected_xml
Expand Down
24 changes: 24 additions & 0 deletions spec/unit/braintree/local_payment_expired_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")

describe Braintree::LocalPaymentExpired do
describe "self.new" do
it "is protected" do
expect do
Braintree::LocalPaymentExpired.new
end.to raise_error(NoMethodError, /protected method .new/)
end
end

describe "self._new" do
it "initializes the object with the appropriate attributes set" do
params = {
payment_id: "a-payment-id",
payment_context_id: "a-payment-context-id",
}
local_payment_expired = Braintree::LocalPaymentExpired._new(params)

local_payment_expired.payment_id.should eq("a-payment-id")
local_payment_expired.payment_context_id.should eq("a-payment-context-id")
end
end
end
34 changes: 34 additions & 0 deletions spec/unit/braintree/local_payment_funded_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")

describe Braintree::LocalPaymentFunded do
describe "self.new" do
it "is protected" do
expect do
Braintree::LocalPaymentFunded.new
end.to raise_error(NoMethodError, /protected method .new/)
end
end

describe "self._new" do
it "initializes the object with the appropriate attributes set" do
params = {
payment_id: "a-payment-id",
payment_context_id: "a-payment-context-id",
transaction: {
id: "a-transaction-id",
amount: "31.00",
order_id: "an-order-id",
status: Braintree::Transaction::Status::Settled,
},
}
local_payment_funded = Braintree::LocalPaymentFunded._new(params)

local_payment_funded.payment_id.should eq("a-payment-id")
local_payment_funded.payment_context_id.should eq("a-payment-context-id")
local_payment_funded.transaction.id.should eq("a-transaction-id")
local_payment_funded.transaction.amount.should eq(31.0)
local_payment_funded.transaction.order_id.should eq("an-order-id")
local_payment_funded.transaction.status.should eq(Braintree::Transaction::Status::Settled)
end
end
end
35 changes: 34 additions & 1 deletion spec/unit/braintree/webhook_notification_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -668,14 +668,47 @@
end
end

context "local_payment_expired" do
it "builds a sample notification for a local_payment_expired webhook" do
sample_notification = Braintree::WebhookTesting.sample_notification(
Braintree::WebhookNotification::Kind::LocalPaymentExpired,
"my_id",
)

notification = Braintree::WebhookNotification.parse(sample_notification[:bt_signature], sample_notification[:bt_payload])
notification.kind.should == Braintree::WebhookNotification::Kind::LocalPaymentExpired

local_payment_expired = notification.local_payment_expired
local_payment_expired.payment_id.should == "PAY-XYZ123"
local_payment_expired.payment_context_id.should == "cG5b="
end
end

context "local_payment_funded" do
it "builds a sample notification for a local_payment_funded webhook" do
sample_notification = Braintree::WebhookTesting.sample_notification(
Braintree::WebhookNotification::Kind::LocalPaymentFunded,
"my_id",
)
notification = Braintree::WebhookNotification.parse(sample_notification[:bt_signature], sample_notification[:bt_payload])
notification.kind.should == Braintree::WebhookNotification::Kind::LocalPaymentFunded

local_payment_funded = notification.local_payment_funded
local_payment_funded.payment_id.should == "PAY-XYZ123"
local_payment_funded.payment_context_id.should == "cG5b="
local_payment_funded.transaction.id.should == "my_id"
local_payment_funded.transaction.status.should == Braintree::Transaction::Status::Settled
local_payment_funded.transaction.amount.should == 49.99
local_payment_funded.transaction.order_id.should == "order4567"
end
end

context "local_payment_reversed" do
it "builds a sample notification for a local_payment webhook" do
sample_notification = Braintree::WebhookTesting.sample_notification(
Braintree::WebhookNotification::Kind::LocalPaymentReversed,
"my_id",
)

notification = Braintree::WebhookNotification.parse(sample_notification[:bt_signature], sample_notification[:bt_payload])
notification.kind.should == Braintree::WebhookNotification::Kind::LocalPaymentReversed

Expand Down

0 comments on commit 7d4182b

Please sign in to comment.