Skip to content

Commit

Permalink
2.45.0
Browse files Browse the repository at this point in the history
  • Loading branch information
braintreeps committed Jun 3, 2015
1 parent c5038b8 commit 592616e
Show file tree
Hide file tree
Showing 14 changed files with 162 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.rdoc
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
== 2.45.0
* Add support for Android Pay

== 2.44.0
* Validate webhook challenge payload
* Changed CreditCardVerification::Status constants
Expand Down
2 changes: 2 additions & 0 deletions lib/braintree.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
require "braintree/address/country_names"
require "braintree/address_gateway"
require "braintree/advanced_search"
require "braintree/android_pay_card"
require "braintree/apple_pay_card"
require "braintree/client_token"
require "braintree/client_token_gateway"
Expand Down Expand Up @@ -89,6 +90,7 @@
require "braintree/test_transaction"
require "braintree/transaction/address_details"
require "braintree/transaction/apple_pay_details"
require "braintree/transaction/android_pay_details"
require "braintree/transaction/coinbase_details"
require "braintree/transaction/credit_card_details"
require "braintree/transaction/customer_details"
Expand Down
35 changes: 35 additions & 0 deletions lib/braintree/android_pay_card.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module Braintree
class AndroidPayCard
include BaseModule # :nodoc:

attr_reader :token, :virtual_card_type, :virtual_card_last_4, :source_card_type, :source_card_last_4,
:expiration_month, :expiration_year, :created_at, :updated_at, :image_url, :subscriptions, :bin,
:google_transaction_id, :default

def initialize(gateway, attributes) # :nodoc:
@gateway = gateway
set_instance_variables_from_hash(attributes)
@subscriptions = (@subscriptions || []).map { |subscription_hash| Subscription._new(@gateway, subscription_hash) }
end

def default?
@default
end

def card_type
virtual_card_type
end

def last_4
virtual_card_last_4
end

class << self
protected :new
end

def self._new(*args) # :nodoc:
self.new *args
end
end
end
4 changes: 3 additions & 1 deletion lib/braintree/customer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ class Customer
include BaseModule

attr_reader :addresses, :company, :created_at, :credit_cards, :email, :fax, :first_name, :id, :last_name,
:phone, :updated_at, :website, :custom_fields, :paypal_accounts, :apple_pay_cards, :coinbase_accounts
:phone, :updated_at, :website, :custom_fields, :paypal_accounts, :apple_pay_cards, :coinbase_accounts,
:android_pay_cards

def self.all
Configuration.gateway.customer.all
Expand Down Expand Up @@ -90,6 +91,7 @@ def initialize(gateway, attributes) # :nodoc:
@coinbase_accounts = (@coinbase_accounts || []).map { |pm| CoinbaseAccount._new gateway, pm }
@apple_pay_cards = (@apple_pay_cards || []).map { |pm| ApplePayCard._new gateway, pm }
@europe_bank_accounts = (@europe_bank_Accounts || []).map { |pm| EuropeBankAccount._new gateway, pm }
@android_pay_cards = (@android_pay_cards || []).map { |pm| AndroidPayCard._new gateway, pm }
@addresses = (@addresses || []).map { |addr| Address._new gateway, addr }
@custom_fields = attributes[:custom_fields].is_a?(Hash) ? attributes[:custom_fields] : {}
end
Expand Down
1 change: 1 addition & 0 deletions lib/braintree/payment_instrument_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ module PaymentInstrumentType
CreditCard = 'credit_card'
CoinbaseAccount = 'coinbase_account'
ApplePayCard = 'apple_pay_card'
AndroidPayCard = 'android_pay_card'
end
end
4 changes: 4 additions & 0 deletions lib/braintree/payment_method_gateway.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ def _do_create(url, params=nil) # :nodoc:
SuccessfulResult.new(:payment_method => EuropeBankAccount._new(@gateway, response[:europe_bank_account]))
elsif response[:apple_pay_card]
SuccessfulResult.new(:payment_method => ApplePayCard._new(@gateway, response[:apple_pay_card]))
elsif response[:android_pay_card]
SuccessfulResult.new(:payment_method => AndroidPayCard._new(@gateway, response[:android_pay_card]))
elsif response[:api_error_response]
ErrorResult.new(@gateway, response[:api_error_response])
elsif response
Expand All @@ -48,6 +50,8 @@ def find(token)
EuropeBankAccount._new(@gateway, response[:europe_bank_account])
elsif response.has_key?(:apple_pay_card)
ApplePayCard._new(@gateway, response[:apple_pay_card])
elsif response.has_key?(:android_pay_card)
AndroidPayCard._new(@gateway, response[:android_pay_card])
else
UnknownPaymentMethod._new(@gateway, response)
end
Expand Down
1 change: 1 addition & 0 deletions lib/braintree/test/nonce.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module Nonce
AbstractTransactable = "fake-abstract-transactable-nonce"
Europe = "fake-europe-bank-account-nonce"
Coinbase = "fake-coinbase-nonce"
AndroidPay = "fake-android-pay-nonce"
end
end
end
2 changes: 2 additions & 0 deletions lib/braintree/transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ module Type # :nodoc:
attr_reader :billing_details, :shipping_details
attr_reader :paypal_details
attr_reader :apple_pay_details
attr_reader :android_pay_details
attr_reader :coinbase_details
attr_reader :plan_id
# The authorization code from the processor.
Expand Down Expand Up @@ -232,6 +233,7 @@ def initialize(gateway, attributes) # :nodoc:
@descriptor = Descriptor.new(@descriptor)
@paypal_details = PayPalDetails.new(@paypal)
@apple_pay_details = ApplePayDetails.new(@apple_pay)
@android_pay_details = AndroidPayDetails.new(@android_pay_card)
@coinbase_details = CoinbaseDetails.new(@coinbase_account)
disputes.map! { |attrs| Dispute._new(attrs) } if disputes
@custom_fields = attributes[:custom_fields].is_a?(Hash) ? attributes[:custom_fields] : {}
Expand Down
16 changes: 16 additions & 0 deletions lib/braintree/transaction/android_pay_details.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module Braintree
class Transaction
class AndroidPayDetails
include BaseModule

attr_reader :card_type, :last_4, :expiration_month, :expiration_year,
:google_transaction_id, :virtual_card_type, :virtual_card_last_4

def initialize(attributes)
set_instance_variables_from_hash attributes unless attributes.nil?
@card_type = @virtual_card_type
@last_4 = @virtual_card_last_4
end
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 = 2
Minor = 44
Minor = 45
Tiny = 0

String = "#{Major}.#{Minor}.#{Tiny}"
Expand Down
14 changes: 14 additions & 0 deletions spec/integration/braintree/customer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,20 @@
apple_pay_card.payment_instrument_name.should == "AmEx 41002"
end

it "returns associated AndroidPayCards" do
result = Braintree::Customer.create(
:payment_method_nonce => Braintree::Test::Nonce::AndroidPay
)
result.success?.should == true

found_customer = Braintree::Customer.find(result.customer.id)
found_customer.android_pay_cards.should_not be_nil
android_pay_card = found_customer.android_pay_cards.first
android_pay_card.should be_a Braintree::AndroidPayCard
android_pay_card.token.should_not be_nil
android_pay_card.expiration_year.should_not be_nil
end

it "works for a blank customer" do
created_customer = Braintree::Customer.create!
found_customer = Braintree::Customer.find(created_customer.id)
Expand Down
7 changes: 7 additions & 0 deletions spec/integration/braintree/merchant_account_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
context "funding destination" do
it "accepts a bank" do
params = VALID_APPLICATION_PARAMS.dup
params[:funding] = VALID_APPLICATION_PARAMS[:funding].dup
params[:funding][:destination] = ::Braintree::MerchantAccount::FundingDestination::Bank
result = Braintree::MerchantAccount.create(params)

Expand All @@ -117,6 +118,9 @@

it "accepts an email" do
params = VALID_APPLICATION_PARAMS.dup
params[:funding] = VALID_APPLICATION_PARAMS[:funding].dup
params[:funding].delete(:routing_number)
params[:funding].delete(:account_number)
params[:funding][:destination] = ::Braintree::MerchantAccount::FundingDestination::Email
params[:funding][:email] = "joebloggs@compuserve.com"
result = Braintree::MerchantAccount.create(params)
Expand All @@ -126,6 +130,9 @@

it "accepts a mobile_phone" do
params = VALID_APPLICATION_PARAMS.dup
params[:funding] = VALID_APPLICATION_PARAMS[:funding].dup
params[:funding].delete(:routing_number)
params[:funding].delete(:account_number)
params[:funding][:destination] = ::Braintree::MerchantAccount::FundingDestination::MobilePhone
params[:funding][:mobile_phone] = "3125882300"
result = Braintree::MerchantAccount.create(params)
Expand Down
53 changes: 53 additions & 0 deletions spec/integration/braintree/payment_method_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@

result.should be_success
apple_pay_card = result.payment_method
apple_pay_card.should be_a(Braintree::ApplePayCard)
apple_pay_card.should_not be_nil
apple_pay_card.token.should == token
apple_pay_card.card_type.should == Braintree::ApplePayCard::CardType::AmEx
Expand All @@ -93,6 +94,31 @@
apple_pay_card.expiration_year.to_i.should > 0
end

it "creates a payment method from a fake android pay nonce" do
customer = Braintree::Customer.create.customer
token = SecureRandom.hex(16)
result = Braintree::PaymentMethod.create(
:payment_method_nonce => Braintree::Test::Nonce::AndroidPay,
:customer_id => customer.id,
:token => token
)

result.should be_success
android_pay_card = result.payment_method
android_pay_card.should be_a(Braintree::AndroidPayCard)
android_pay_card.should_not be_nil
android_pay_card.token.should == token
android_pay_card.card_type.should == Braintree::CreditCard::CardType::Discover
android_pay_card.virtual_card_type.should == Braintree::CreditCard::CardType::Discover
android_pay_card.expiration_month.to_i.should > 0
android_pay_card.expiration_year.to_i.should > 0
android_pay_card.default.should == true
android_pay_card.image_url.should =~ /android_pay/
android_pay_card.source_card_type.should == Braintree::CreditCard::CardType::Visa
android_pay_card.source_card_last_4.should == "1111"
android_pay_card.google_transaction_id.should == "google_transaction_id"
end

it "allows passing the make_default option alongside the nonce" do
customer = Braintree::Customer.create!
result = Braintree::CreditCard.create(
Expand Down Expand Up @@ -592,6 +618,33 @@
end
end

context "android pay cards" do
it "finds the payment method with the given token" do
customer = Braintree::Customer.create!
payment_method_token = "PAYMENT_METHOD_TOKEN_#{rand(36**3).to_s(36)}"
result = Braintree::PaymentMethod.create(
:payment_method_nonce => Braintree::Test::Nonce::AndroidPay,
:customer_id => customer.id,
:token => payment_method_token
)
result.should be_success

android_pay_card = Braintree::PaymentMethod.find(payment_method_token)
android_pay_card.should be_a(Braintree::AndroidPayCard)
android_pay_card.should_not be_nil
android_pay_card.token.should == payment_method_token
android_pay_card.card_type.should == Braintree::CreditCard::CardType::Discover
android_pay_card.virtual_card_type.should == Braintree::CreditCard::CardType::Discover
android_pay_card.expiration_month.to_i.should > 0
android_pay_card.expiration_year.to_i.should > 0
android_pay_card.default.should == true
android_pay_card.image_url.should =~ /android_pay/
android_pay_card.source_card_type.should == Braintree::CreditCard::CardType::Visa
android_pay_card.source_card_last_4.should == "1111"
android_pay_card.google_transaction_id.should == "google_transaction_id"
end
end

context "unknown payment methods" do
it "finds the payment method with the given token" do
customer = Braintree::Customer.create!
Expand Down
20 changes: 20 additions & 0 deletions spec/integration/braintree/transaction_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1270,6 +1270,26 @@
apple_pay_details.cardholder_name.should_not be_nil
end

it "can create a transaction with a fake android pay nonce" do
customer = Braintree::Customer.create!
result = Braintree::Transaction.create(
:type => "sale",
:amount => Braintree::Test::TransactionAmounts::Authorize,
:payment_method_nonce => Braintree::Test::Nonce::AndroidPay
)
result.success?.should == true
result.transaction.should_not be_nil
android_pay_details = result.transaction.android_pay_details
android_pay_details.should_not be_nil
android_pay_details.card_type.should == Braintree::CreditCard::CardType::Discover
android_pay_details.virtual_card_type.should == Braintree::CreditCard::CardType::Discover
android_pay_details.last_4.should == "1117"
android_pay_details.virtual_card_last_4.should == "1117"
android_pay_details.expiration_month.to_i.should > 0
android_pay_details.expiration_year.to_i.should > 0
android_pay_details.google_transaction_id.should == "google_transaction_id"
end

it "can create a transaction with an unknown nonce" do
customer = Braintree::Customer.create!
result = Braintree::Transaction.create(
Expand Down

0 comments on commit 592616e

Please sign in to comment.