GithubHelp home page GithubHelp logo

braintree / braintree_ruby Goto Github PK

View Code? Open in Web Editor NEW
444.0 95.0 195.0 2.38 MB

Braintree Ruby library

Home Page: https://developer.paypal.com/braintree/docs/start/overview

License: MIT License

Ruby 99.94% Shell 0.01% Makefile 0.02% Dockerfile 0.03%
braintree ruby payments

braintree_ruby's Introduction

Braintree Ruby library

The Braintree gem provides integration access to the Braintree Gateway.

Please Note

The Payment Card Industry (PCI) Council has mandated that early versions of TLS be retired from service. All organizations that handle credit card information are required to comply with this standard. As part of this obligation, Braintree is updating its services to require TLS 1.2 for all HTTPS connections. Braintree will also require HTTP/1.1 for all connections. Please see our technical documentation for more information.

Installation

gem install braintree

Or add to your Gemfile:

gem 'braintree'

Optionally, you may also include LibXML for more performant XML parsing. If LibXML is not present, REXML will be used instead.

gem 'libxml-ruby'

Dependencies

  • builder

The Braintree Ruby SDK is tested against Ruby versions 2.6, 2.7 and 3.0.

The Ruby core development community has released End-of-Life branches for Ruby versions lower than 2.6, which are no longer receiving security updates. As a result, Braintree no longer supports these versions of Ruby. We have updated our gem specifications to reflect these updates.

Versions

Braintree employs a deprecation policy for our SDKs. For more information on the statuses of an SDK check our developer docs. Minimum supported versions are also available in our developer docs.

Major version number Status Released Deprecated Unsupported
4.x.x Active May 2021 TBA TBA
3.x.x Deprecated October 2020 May 2023 May 2024
2.x.x Deprecated April 2010 October 2022 October 2023

Documentation

Updating from an Inactive, Deprecated, or Unsupported version of this SDK? Check our Migration Guide for tips.

Quick Start Example

require "rubygems"
require "braintree"

gateway = Braintree::Gateway.new(
  :environment => :sandbox,
  :merchant_id => "your_merchant_id",
  :public_key => "your_public_key",
  :private_key => "your_private_key",
)

result = gateway.transaction.sale(
  :amount => "1000.00",
  :payment_method_nonce => nonce_from_the_client,
  :options => {
    :submit_for_settlement => true
  }
)

if result.success?
  puts "success!: #{result.transaction.id}"
elsif result.transaction
  puts "Error processing transaction:"
  puts "  code: #{result.transaction.processor_response_code}"
  puts "  text: #{result.transaction.processor_response_text}"
else
  p result.errors
end

You retrieve your merchant_id, public_key, and private_key when signing up for Braintree. Signing up for a sandbox account is easy, free, and instant.

Bang Methods

Most methods have a bang and a non-bang version (e.g. gateway.customer.create and gateway.customer.create!). The non-bang version will either return a SuccessfulResult or an ErrorResult. The bang version will either return the created or updated resource, or it will raise a ValidationsFailed exception.

Example of using non-bang method:

result = gateway.customer.create(:first_name => "Josh")
if result.success?
  puts "Created customer #{result.customer.id}"
else
  puts "Validations failed"
  result.errors.for(:customer).each do |error|
    puts error.message
  end
end

Example of using bang method:

begin
  customer = gateway.customer.create!(:first_name => "Josh")
  puts "Created customer #{customer.id}"
rescue Braintree::ValidationsFailed
  puts "Validations failed"
end

We recommend using the bang methods when you assume that the data is valid and do not expect validations to fail. Otherwise, we recommend using the non-bang methods.

Developing (Docker)

The Makefile and Dockerfile will build an image containing the dependencies and drop you to a terminal where you can run tests.

make

Linting

The Rakefile includes commands to run Rubocop. To run the linter commands use rake: rake lint.

Tests

The unit specs can be run by anyone on any system, but the integration specs are meant to be run against a local development server of our gateway code. These integration specs are not meant for public consumption and will likely fail if run on your system. To run unit tests use rake: rake test:unit.

Suppress Braintree Logs

To suppress logs from Braintree on environments where they are considered noise (e.g. test) use the following configuration:

logger = Logger.new("/dev/null")
logger.level = Logger::INFO
gateway.config.logger = logger

License

See the LICENSE file for more info.

braintree_ruby's People

Contributors

axelthegerman avatar badosu avatar braintreeps avatar brianlima avatar cdpalmer avatar cwalsh avatar dmytrostepaniuk avatar hollabaq86 avatar kate-paypal avatar kinduff avatar kinkade avatar kjperry avatar ktransier avatar lkorth avatar mcls avatar michaelfairley avatar nickmele avatar nzkoz avatar olleolleolle avatar radar avatar regismesquita avatar rochers avatar saralvasquez avatar sestevens avatar shayfrendt avatar sshropshire avatar tonkpils avatar viraptor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

braintree_ruby's Issues

Autoloading

The braintree gem loads everything when my Rails app starts up, but it does not need to. Instead, it can setup autoloads, and only load itself when actually needed. Switching to gems that use autoload has sped up my individual test runs and my development server startup. I am hoping that braintree_ruby can also take advantage of this ruby feature. See below diff:

https://github.com/matthuhiggins/braintree_ruby/commit/5970a06153c0c69d00b5ea5bebd57889163d0647

Additionally, the requires at the top of braintree.rb can be moved to the individual files that actually need them. This step is only beneficial if autoloads are first setup.

Thanks!

Error Saving data using ruby code

Hi,

I am using ios sdk to post data to my ruby on rails server using the code provided, the data is posted successfully but the problem is that I get the following error:

response: {
error = "CVV must be 4 digits for American Express and 3 digits for other card types.\nExpiration year is invalid.\nExpiration month is invalid.\nCredit card number must be 12-19 digits.\nPostal code can only contain letters, numbers, spaces, and hyphens.\nPostal code may contain no more than 9 letter or number characters.";
success = 0;
}, error: (null)

The data is going in encrypted form, can this be the issue?

Thanks,
Talal

Configuring the gem in a thread-safe way

I'm working on an app where we have per-publisher Braintree settings where each request may have a different publisher. Setting class variables (as far as I know) is not thread-safe. Do you have a suggested or common way to make it thread safe?

I was thinking about creating a #with_braintree method that will wrap the thing I'm doing with Braintree and the configuration in a mutex.

Promo Code

Hi,

Could anyone please tell me how can I create promo code?

Thanks in advance

Rack endpoint for transparent redirects

It would be great if you could provide some kind of rack system for users of this library to test transparent redirects. It's taking a lot of hackery on my end to get integration tests workings with transparent redirect

License missing from gemspec

RubyGems.org doesn't report a license for your gem. This is because it is not specified in the gemspec of your last release.

via e.g.

spec.license = 'MIT'
# or
spec.licenses = ['MIT', 'GPL-2']

Including a license in your gemspec is an easy way for rubygems.org and other tools to check how your gem is licensed. As you can imagine, scanning your repository for a LICENSE file or parsing the README, and then attempting to identify the license or licenses is much more difficult and more error prone. So, even for projects that already specify a license, including a license in your gemspec is a good practice. See, for example, how rubygems.org uses the gemspec to display the rails gem license.

There is even a License Finder gem to help companies/individuals ensure all gems they use meet their licensing needs. This tool depends on license information being available in the gemspec. This is an important enough issue that even Bundler now generates gems with a default 'MIT' license.

I hope you'll consider specifying a license in your gemspec. If not, please just close the issue with a nice message. In either case, I'll follow up. Thanks for your time!

Appendix:

If you need help choosing a license (sorry, I haven't checked your readme or looked for a license file), GitHub has created a license picker tool. Code without a license specified defaults to 'All rights reserved'-- denying others all rights to use of the code.
Here's a list of the license names I've found and their frequencies

p.s. In case you're wondering how I found you and why I made this issue, it's because I'm collecting stats on gems (I was originally looking for download data) and decided to collect license metadata,too, and make issues for gemspecs not specifying a license as a public service :). See the previous link or my blog post about this project for more information.

Find discount with ID.

Hey guys, is there any way to retrieve a discount based on its id? e.g Braintree::Discount.find("the-discount-id")? I'm reviewing the gem code/docs and I can't find something like this, how can I achieve it? thanks!

Unable to serialize to JSON

It's not currently possible to serialize Both Braintree::Customer and Braintree::CreditCard. E.g. MultiJson.dump(brain_tree_customer) fails because the instances are not serializable.
I'm currently using the following monkey patch. If it makes sense, I can create a pull request.

class Braintree::Customer
  def as_json(options = nil)
    {
                 "id" => id,
         "first_name" => first_name,
          "last_name" => last_name,
            "company" => company,
              "email" => email,
              "phone" => phone,
                "fax" => fax,
            "website" => website,
      "custom_fields" => custom_fields.as_json,
       "credit_cards" => credit_cards.map(&:as_json),
          "addresses" => addresses.map(&:as_json),
         "created_at" => created_at.as_json,
         "updated_at" => updated_at.as_json
    }
  end
end

class Braintree::CreditCard
  def as_json(options = nil)
    {
                     "bin" => bin,
               "card_type" => card_type,
         "cardholder_name" => cardholder_name,
              "commercial" => commercial,
     "country_of_issuance" => country_of_issuance,
             "customer_id" => customer_id,
                   "debit" => debit,
                 "default" => default?,
        "durbin_regulated" => durbin_regulated,
        "expiration_month" => expiration_month,
         "expiration_year" => expiration_year,
                 "expired" => expired?,
              "healthcare" => healthcare,
               "image_url" => image_url,
            "issuing_bank" => issuing_bank,
                  "last_4" => last_4,
                 "payroll" => payroll,
                 "prepaid" => prepaid,
           "subscriptions" => subscriptions.map(&:as_json),
                   "token" => token,
"unique_number_identifier" => unique_number_identifier,
               "venmo_sdk" => venmo_sdk?,
         "billing_address" => billing_address,
              "created_at" => created_at.as_json,
              "updated_at" => updated_at.as_json
    }
  end
end

405 on updating credit card info

I'm getting Unexpected HTTP_RESPONSE 405 (Braintree::UnexpectedError) from the Braintree::TransparentRedirect.confirm method.

According to this page, 405's should only happen if there's a bug in the library: https://www.braintreepayments.com/docs/ruby/general/exceptions

But it looks like the server is returning the 405 and the library is just raising it on confirm.

here are the params i'm getting before i do my confirm

{"http_status"=>"405", "hash"=>"07438914a9a550be9fb60163e42ca189ed89ec5e", "action"=>"confirm", "controller"=>"subscriptions"}

here's my redirect data:

Braintree::TransparentRedirect.update_credit_card_data(
  :redirect_url => url_for(controller: '/subscriptions', action: 'confirm', only_path: false),
  :payment_method_token => current_user.billing_information.braintree_payment_method_token,
  :credit_card => {
    :billing_address => {
      :options => {
        :update_existing => true
      }
    }
  }
)

here's what the post I'm sending to the transparent redirect looks like (minus my public key)

    {"utf8"=>"βœ“",
 "_method"=>"put",
 "authenticity_token"=>"6d8pw8D6GdcNb9+QJca1MUXRMj+1w2ZngmS7x1HXUpg=",
 "modal"=>"edit-billing-information",
 "credit_card"=>
  {"billing_address"=>
    {"first_name"=>"Jeffrey",
     "last_name"=>"Chupp",
     "street_address"=>"123 fake street",
     "extended_address"=>"Apt A",
     "locality"=>"Brookline",
     "region"=>"MA",
     "postal_code"=>"02446"},
   "number"=>"5105105105105100",
   "expiration_month"=>"4",
   "expiration_year"=>"2015",
   "cvv"=>"123"},
 "tr_data"=>
  "8753a08f6638c63485c47c5dcee98eb5c3b4e4a3|api_version=2&credit_card%5Bbilling_address%5D%5Boptions%5D%5Bupdate_existing%5D=true&kind=update_payment_method&payment_method_token=2y7pp&public_key=_SNIP_&redirect_url=http%3A%2F%2Flocalhost%3A3000%2Fsubscriptions%2Fconfirm&time=20120515214300",
 "commit"=>"Update credit card info",
 }

I can post any other info as needed, but I'm not sure what will be helpful... Any help would be much appreciated

Discount Current Billing Cycle

Hi there, I think this is a bug but I'm not 100% sure. If I look at the discount object returned it shows

  • !ruby/object:Braintree::Discount
    amount: 5.0
    current_billing_cycle: 0
    id: j_199_discount
    never_expires: false
    number_of_billing_cycles: 3
    quantity: 1

But if I try to do discount.current_billing_cycle I get:

undefined method `current_billing_cycle' for #Braintree::Discount:0x10663c200

Thanks for your help.

Settled at date

Hi,

Is there possibility to fetch (display) settled at date from a single transaction?

Paypal details doc incorrect

Hello,
I am trying to get the email address from a paypal transaction and according to the docs (https://developers.braintreepayments.com/javascript+ruby/reference/objects/transaction) it states that paypal_details.email should return the email belonging to the paypal account. When calling .paypal_details.email on a transaction result I get an undefined method exception:
NoMethodError - undefined method `email' for #Braintree::Transaction::PayPalDetails:0x007f5ed03ed1a0
After looking at the source, paypal_details.rb does not have an attr_reader for email which leads me to believe the docs are incorrect?

The documentation doesn't explain how to set currencies

I need to accept payments in currencies other than USD. I can see a nice long list of currency codes, but no documentation explaining how to set the the currency for a transaction.

In Ruby I tried
Braintree::Transaction.sale(:amount=>'10',:currency=>'GBP',etc

and got an error saying that :currency is an invalid key.

So if currency isn't specified along with the amount where is it specific. In the address?

The documents need to be amended to tell people how to specify currencies.

Thanks

John Small

`confirm_payment_url'

i've successfully implemented the braintree gem in one of my apps but on another i'm getting the following error:

undefined local variable or method `confirm_payment_url'

and can't find the fix. i've copied the provided example and this error occurs when rendering payment/new. any help would be appreciated. thanks!

Customer data containing html_safe buffer does not url encode

It so happens that we encode business name in the customer_create_data .

The business's name happens to be a html_safe buffer (to ensure that ampersands in name remain in tact).

This raises an error NoMethodError: undefined methodbytesize' for nil:NilClass`

The workaround is to explicitly do .to_str on the safe buffer. Could this possibly be handled by Braintree instead?

Ruby 2 - Braintree::UnexpectedError: expected a gzipped response

Hi, I get this everytime on ruby 2 :

Braintree::UnexpectedError: expected a gzipped response
    /Users/iRyusa/.rvm/gems/ruby-head/gems/braintree-2.16.0/lib/braintree/http.rb:85:in `_body'
    /Users/iRyusa/.rvm/gems/ruby-head/gems/braintree-2.16.0/lib/braintree/http.rb:75:in `block in _http_do'
    /Users/iRyusa/.rvm/rubies/ruby-head/lib/ruby/2.0.0/net/http.rb:851:in `start'
    /Users/iRyusa/.rvm/gems/ruby-head/gems/braintree-2.16.0/lib/braintree/http.rb:58:in `_http_do'
    /Users/iRyusa/.rvm/gems/ruby-head/gems/braintree-2.16.0/lib/braintree/http.rb:27:in `post'
    /Users/iRyusa/.rvm/gems/ruby-head/gems/braintree-2.16.0/lib/braintree/customer_gateway.rb:83:in `_do_create'
    /Users/iRyusa/.rvm/gems/ruby-head/gems/braintree-2.16.0/lib/braintree/customer_gateway.rb:15:in `create'
    /Users/iRyusa/.rvm/gems/ruby-head/gems/braintree-2.16.0/lib/braintree/customer.rb:16:in `create'

A response.inspect return <Net::HTTPOK 200 OK readbody=true> and the header looks empty

Unexpected 'Braintree search exception Unprocessable entity due to an invalid request'

Hi. Without changing anything to my code, for a common Braintree search (like the days before when all worked OK), the response to:
POST /transactions/advanced_search_ids 422
was:
Braintree search exception Unprocessable entity due to an invalid request

Were there made changes of the API in the last 24 hours?
(I even repeated the search with the parameters that worked the days before and got the same error)

Abort trap: 6 when calling Braintree::Customer.find

I am getting this error:

/Users/etagwerker/Projects/lc/app/models/user.rb:86:in customer_exists?' /Users/etagwerker/.rvm/gems/ruby-1.9.2-p180@lc/gems/braintree-2.13.4/lib/braintree/customer.rb:57:infind'
/Users/etagwerker/.rvm/gems/ruby-1.9.2-p180@lc/gems/braintree-2.13.4/lib/braintree/customer_gateway.rb:37:in find' /Users/etagwerker/.rvm/gems/ruby-1.9.2-p180@lc/gems/braintree-2.13.4/lib/braintree/http.rb:18:inget'
/Users/etagwerker/.rvm/gems/ruby-1.9.2-p180@lc/gems/braintree-2.13.4/lib/braintree/http.rb:58:in _http_do' /Users/etagwerker/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/net/http.rb:626:instart'
/Users/etagwerker/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/net/http.rb:637:in do_start' /Users/etagwerker/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/net/http.rb:678:inconnect'
/Users/etagwerker/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/timeout.rb:87:in timeout' /Users/etagwerker/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/timeout.rb:44:intimeout'
/Users/etagwerker/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/net/http.rb:678:in block in connect' /Users/etagwerker/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/net/http.rb:678:inconnect'

-- C level backtrace information -------------------------------------------
0 libruby.1.9.1.dylib 0x0025a5f6 rb_vm_bugreport + 230
1 libruby.1.9.1.dylib 0x00103afc report_bug + 364
2 libruby.1.9.1.dylib 0x00103bab rb_bug + 43
3 libruby.1.9.1.dylib 0x001d1cab sigbus + 27
4 libsystem_c.dylib 0x9ba7659b _sigtramp + 43
5 ??? 0xffffffff 0x0 + 4294967295
6 libcrypto.0.9.8.dylib 0x00619923 internal_verify + 235

[NOTE]
You may have encountered a bug in the Ruby interpreter or extension libraries.
Bug reports are welcome.
For details: http://www.ruby-lang.org/bugreport.html

Abort trap: 6

My application code doesn't do anything fancy, just:

Braintree::Customer.find(self.id.to_s)

I realize that it could be a problem with the net/http library, but do you have any ideas why it's failing?

Thanks!

There are never transactions when generating a sample webhook notification for SubscriptionChargedSuccessfully

Knowing how much the user was charged can be a key reason for consuming a webhook notification for SubscriptionChargedSuccessfully (i.e. tracking revenue per use internally).

When generating a sample webhook notification for this using Braintree::WebhookTesting - a subscription comes back with the webhook payload, but no transactions are ever a part of that webhook.

This subscription within the notification payload should contain a fake Transaction that includes a charged amount.

No error reported on duplicate transations

When I try this:

result = Braintree::Transaction.sale(
  :amount => "1000.00",
  :credit_card => {
    :number => "5105105105105100",
    :expiration_date => "05/12"
  }
)
 => #<Braintree::SuccessfulResult transaction:#<Braintree::Transaction id: "87g4yb", type: "sale", amount: "1000.0", status: "authorized", created_at: Wed Jan 26 01:15:38 UTC 2011, credit_card_details: #<token: nil, bin: "510510", last_4: "5100", card_type: "MasterCard", expiration_date: "05/2012", cardholder_name: nil, customer_location: "US">, customer_details: #<id: nil, first_name: nil, last_name: nil, email: nil, company: nil, website: nil, phone: nil, fax: nil>, updated_at: Wed Jan 26 01:15:39 UTC 2011>> 
result = Braintree::Transaction.sale(
  :amount => "1000.00",
  :credit_card => {
    :number => "5105105105105100",
    :expiration_date => "05/12"
  }
)
 => #<Braintree::ErrorResult params:{...} errors:<> transaction: #<Braintree::Transaction id: "hzt92m", type: "sale", amount: "1000.0", status: "gateway_rejected", created_at: Wed Jan 26 01:15:44 UTC 2011, credit_card_details: #<token: nil, bin: "510510", last_4: "5100", card_type: "MasterCard", expiration_date: "05/2012", cardholder_name: nil, customer_location: "US">, customer_details: #<id: nil, first_name: nil, last_name: nil, email: nil, company: nil, website: nil, phone: nil, fax: nil>, updated_at: Wed Jan 26 01:15:44 UTC 2011>> 
result.errors
 => #<Braintree::Errors > 
p result.errors
#<Braintree::Errors >
result.transaction
 => #<Braintree::Transaction id: "hzt92m", type: "sale", amount: "1000.0", status: "gateway_rejected", created_at: Wed Jan 26 01:15:44 UTC 2011, credit_card_details: #<token: nil, bin: "510510", last_4: "5100", card_type: "MasterCard", expiration_date: "05/2012", cardholder_name: nil, customer_location: "US">, customer_details: #<id: nil, first_name: nil, last_name: nil, email: nil, company: nil, website: nil, phone: nil, fax: nil>, updated_at: Wed Jan 26 01:15:44 UTC 2011> 
result.transaction.processor_response_text
 => "Unknown ()" 
result.transaction.processor_response_code
 => "" 

Basically: if anyone tries to send a payment twice in a row, the gateway will reject the second payment, but the gem won't capture any errors.

Any tips for running integration specs against an arbitrary server?

Related to #26, I'd like to run the Braintree integration specs against fake_braintree, but (understandably!) it makes a lot of assumptions about the testing server (e.g. it's on localhost, it's SSL, etc) instead of using e.g. Braintree::Sale.new. Is there a way to easily make it hit my server? Are you interested in working together to make it easier to use in external tests?

Custom Fields for Transactions via Subscriptions?

Hey guys,

According to these docs custom fields can be associated with newly created transactions or customer vault records. So I'm wondering how should I pass the custom fields for a transaction that's being created via a subscription#create operation, seems like Braintree::Subscription.create doesn't support the :custom_fields option and based in the docs it makes sense for me, but then how should achieve this? any help would be really appreciated!

to_xs method not defined

Builder 3.0.0 does not define String#to_xs when using Ruby 1.9, which is a problem because braintree_ruby expects this method. builder 3.0.0 checks if String#encode exists, and if it does, defines Builder::XChar.encode instead. (https://github.com/jimweirich/builder/blob/964c68927439d8b83e4a8074470c243a37856edb/lib/builder/xchar.rb#L96)

builder 3.0.0 is the new default for Rails 3.1, so I presume a lot of users will run into this once Rails 3.1 is released. My workaround is manually defining String#to_xs and passing self to Builder::XChar.encode.

[Request] A way to look up existing merchant accounts

Would we be able to add a self.find method to Braintree::MerchantAccount, that looks up data for a merchant account and returns it?

This would be useful if a merchant_account_id is stored in a database, and an application needed to look up the approval status of that merchant, or other similar information.

At the moment, it seems like the only way to do this is to store all of the desired data in the local database immediately after creating the merchant account. This feature would allow an application to only store the account id, and make requests for the other information as needed.

The new method would behave similarly to Braintree::Transaction.find("transaction_id").

Thoughts?
If there's support for this idea, I can start working on it.

Missing method: SuccessfulResult#params

Trying to use this gem in a Rails environment, when I get an ErrorResult back, I can very easily pull form data out via #params, send it to ActiveRecord and let it work (validations, custom code, etc). However, when I get a SuccessfulResult, for some reason #params isn't there and I'm left with having to write even more custom code to parse data out of a nested tree of objects instead.

Please add #params to SuccessfulResult to be consistent with ErrorResult.

NameError: uninitialized constant Braintree::Plan

Can't find the class Braintree::Plan within my rails application, I actually wanted to fetch all the plans created by me, whenever I'm trying to invoke the module Braintree::Plan, it's saying undefined, I tried it both from my application and rails console, I can't find such a class from my rails console, as per the documentation it states that all the plans are retrievable by invoking the following, plans = Braintree::Plan.all by it's returning a NameError: uninitialized constant Braintree::Plan

Braintree::UnexpectedError 422 on transactions search

[33] pry(main)> transactions = Braintree::Transaction.search do |search|
[33] pry(main)* search.settled_at <= day.end_of_day
[33] pry(main)* search.settled_at >= day.beginning_of_day
[33] pry(main)* end
[Braintree] [11/Sep/2013 18:27:24 UTC] POST /transactions/advanced_search_ids 422
Braintree::UnexpectedError: Unprocessable entity due to an invalid request
from /srv/hawser/shared/bundle/ruby/2.0.0/gems/braintree-2.23.0/lib/braintree/util.rb:4:in `extract_attribute_as_array'

possibly related to: #40

Duplicated Constants

Do you have plans to get rid of all the following warning when the gem is loaded? I'd be happy to help, but didn't want to go down the rabbit hole if you guys were already planning on cleaning it up.

warning: already initialized constant API_VERSION
s/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:7: warning: already initialized constant CannotBeBlank
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:8: warning: already initialized constant CompanyIsTooLong
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:9: warning: already initialized constant CountryNameIsNotAccepted
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:10: warning: already initialized constant ExtendedAddressIsTooLong
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:11: warning: already initialized constant FirstNameIsTooLong
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:12: warning: already initialized constant LastNameIsTooLong
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:13: warning: already initialized constant LocalityIsTooLong
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:14: warning: already initialized constant PostalCodeIsRequired
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:15: warning: already initialized constant PostalCodeIsTooLong
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:16: warning: already initialized constant RegionIsTooLong
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:17: warning: already initialized constant StreetAddressIsRequired
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:18: warning: already initialized constant StreetAddressIsTooLong
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:22: warning: already initialized constant BillingAddressConflict
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:23: warning: already initialized constant BillingAddressIdIsInvalid
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:24: warning: already initialized constant CardholderNameIsTooLong
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:25: warning: already initialized constant CreditCardTypeIsNotAccepted
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:26: warning: already initialized constant CustomerIdIsRequired
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:27: warning: already initialized constant CustomerIdIsInvalid
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:28: warning: already initialized constant CvvIsRequired
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:29: warning: already initialized constant CvvIsInvalid
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:30: warning: already initialized constant ExpirationDateConflict
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:31: warning: already initialized constant ExpirationDateIsRequired
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:32: warning: already initialized constant ExpirationDateIsInvalid
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:33: warning: already initialized constant ExpirationDateYearIsInvalid
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:34: warning: already initialized constant ExpirationMonthIsInvalid
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:35: warning: already initialized constant ExpirationYearIsInvalid
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:36: warning: already initialized constant NumberIsRequired
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:37: warning: already initialized constant NumberIsInvalid
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:38: warning: already initialized constant NumberInvalidLength
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:39: warning: already initialized constant NumberMustBeTestNumber
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:40: warning: already initialized constant TokenInvalid
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:41: warning: already initialized constant TokenIsInUse
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:42: warning: already initialized constant TokenIsTooLong
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:43: warning: already initialized constant TokenIsNotAllowed
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:44: warning: already initialized constant TokenIsRequired
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:48: warning: already initialized constant CompanyisTooLong
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:49: warning: already initialized constant CustomFieldIsInvalid
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:50: warning: already initialized constant CustomFieldIsTooLong
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:51: warning: already initialized constant EmailIsInvalid
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:52: warning: already initialized constant EmailIsTooLong
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:53: warning: already initialized constant EmailIsRequired
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:54: warning: already initialized constant FaxIsTooLong
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:55: warning: already initialized constant FirstNameIsTooLong
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:56: warning: already initialized constant IdIsInUse
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:57: warning: already initialized constant IdIsInvaild
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:58: warning: already initialized constant IdIsNotAllowed
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:59: warning: already initialized constant IdIsTooLong
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:60: warning: already initialized constant LastNameIsTooLong
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:61: warning: already initialized constant PhoneIsTooLong
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:62: warning: already initialized constant WebsiteIsTooLong
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:63: warning: already initialized constant WebsiteIsInvalid
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:67: warning: already initialized constant AmountCannotBeNegative
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:68: warning: already initialized constant AmountIsRequired
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:69: warning: already initialized constant AmountIsInvalid
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:70: warning: already initialized constant CannotBeVoided
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:71: warning: already initialized constant CannotRefundCredit
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:72: warning: already initialized constant CannotRefundUnlessSettled
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:73: warning: already initialized constant CannotSubmitForSettlement
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:74: warning: already initialized constant CreditCardIsRequired
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:75: warning: already initialized constant CustomerDefaultPaymentMethodCardTypeIsNotAccepted
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:76: warning: already initialized constant CustomerIdIsInvalid
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:77: warning: already initialized constant CustomerDoesNotHaveCreditCard
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:78: warning: already initialized constant HasAlreadyBeenRefunded
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:79: warning: already initialized constant MerchantAccountNameIsInvalid
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:80: warning: already initialized constant MerchantAccountIsSuspended
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:81: warning: already initialized constant OrderIdIsTooLong
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:82: warning: already initialized constant PaymentMethodConflict
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:83: warning: already initialized constant PaymentMethodDoesNotBelongToCustomer
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:84: warning: already initialized constant PaymentMethodTokenCardTypeIsNotAccepted
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:85: warning: already initialized constant PaymentMethodTokenIsInvalid
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:86: warning: already initialized constant RefundAmountIsTooLarge
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:87: warning: already initialized constant SettlementAmountIsTooLarge
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:88: warning: already initialized constant TypeIsInvalid
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:89: warning: already initialized constant TypeIsRequired
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/error_codes.rb:91: warning: already initialized constant VaultIsDisabled
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/test/credit_card_numbers.rb:10: warning: already initialized constant AmExes
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/test/credit_card_numbers.rb:12: warning: already initialized constant CarteBlanches
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/test/credit_card_numbers.rb:13: warning: already initialized constant DinersClubs
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/test/credit_card_numbers.rb:17: warning: already initialized constant Discovers
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/test/credit_card_numbers.rb:19: warning: already initialized constant JCBs
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/test/credit_card_numbers.rb:21: warning: already initialized constant MasterCard
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/test/credit_card_numbers.rb:22: warning: already initialized constant MasterCardInternational
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/test/credit_card_numbers.rb:24: warning: already initialized constant MasterCards
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/test/credit_card_numbers.rb:26: warning: already initialized constant Visa
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/test/credit_card_numbers.rb:27: warning: already initialized constant VisaInternational
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/test/credit_card_numbers.rb:33: warning: already initialized constant Visas
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/test/credit_card_numbers.rb:36: warning: already initialized constant Unknowns
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/test/credit_card_numbers.rb:40: warning: already initialized constant AmEx
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/test/credit_card_numbers.rb:41: warning: already initialized constant Discover
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/test/credit_card_numbers.rb:42: warning: already initialized constant MasterCard
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/test/credit_card_numbers.rb:43: warning: already initialized constant Visa
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/test/credit_card_numbers.rb:44: warning: already initialized constant Numbers
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/test/credit_card_numbers.rb:47: warning: already initialized constant All
l/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/test/transaction_amounts.rb:6: warning: already initialized constant Authorize
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/test/transaction_amounts.rb:7: warning: already initialized constant Decline
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/transaction.rb:123: warning: already initialized constant Credit
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/transaction.rb:124: warning: already initialized constant Sale
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/transparent_redirect.rb:22: warning: already initialized constant TransparentRedirectKeys
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/transparent_redirect.rb:23: warning: already initialized constant CreateCustomerSignature
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/transparent_redirect.rb:24: warning: already initialized constant UpdateCustomerSignature
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/transparent_redirect.rb:25: warning: already initialized constant TransactionSignature
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/transparent_redirect.rb:26: warning: already initialized constant CreateCreditCardSignature
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/transparent_redirect.rb:27: warning: already initialized constant UpdateCreditCardSignature
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/version.rb:3: warning: already initialized constant Major
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/version.rb:4: warning: already initialized constant Minor
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/version.rb:5: warning: already initialized constant Tiny
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/version.rb:7: warning: already initialized constant String
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/xml/generator.rb:12: warning: already initialized constant XML_TYPE_NAMES
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/xml/generator.rb:16: warning: already initialized constant XML_FORMATTING
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/xml/libxml.rb:6: warning: already initialized constant LIB_XML_LIMIT
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/xml/parser.rb:5: warning: already initialized constant CONTENT_ROOT
/usr/local/lib/ruby/gems/1.8/gems/braintree-1.0.1/lib/braintree/xml/parser.rb:11: warning: already initialized constant XML_PARSING

unitialized constant Braintree (NameError)

I installed the sample script on my desktop, changed it to match my developer info, and ran using the command line: ruby braintree.rb. I recieved the error listed in my title, and it pointed me back to the custom_require.rb file. I have require 'rubygems' and require 'braintree'. I'm stumped.

masked_number always returns 16 characters even if AMEX?

It seems like masked_number should not blindly return 16 characters because some cards (e.g. AMEX) are only 15. We have some internal verifications on the masked number that freak out a bit at the 16 character AMEX numbers. In the case of an AMEX card could we instead return a 15-character masked number?

Stringly-typed dates w/ time zone confusion

Many attributes, e.g., Subscription#next_billing_date, are strings but would be more useful as Time instances.

It is useful to operate on a time data type in order to calculate prorations or for compatibility with other libraries. Currently the consumer needs to parse the strings into dates.

Confusingly, the dates returned at actually in CST. If the consumer does not realize this, some math might not work out. Amazingly, the time zone is undocumented as well. I finally realized what was going on when a test failed on CI.

I suggest data which are semantically dates would be in a better represented by a type that supported arithmetic operators and included time zone information.

Subscription.all

It is possible to call Braintree::Customer.all, which simply returns a ResourceCollection of all Customer objects created in Braintree. Can you please provide the same for the Subscription object?

Client Side Encryption in the Ruby library?

So for my automated testing I want to create valid test data.

Basically I want to only work with encrypted data, even in my tests.

eg.

When I subscribe with the credit card "4111 1111 1111 1111"
Then I should something something

But in my integration test I have no way to create valid encrypted data to work against.

Basically I want a method like;

Braintree::Testing.encrypted_value("4111 1111 1111 1111")

which can use our Client Side Encryption key and generate us real fake data.

Ruby 1.9.2: invalid multibyte char (US-ASCII) in braintree/address/country_names.rb

/Users/heli/.rvm/gems/ruby-1.9.2-p0/gems/braintree-2.6.0/lib/braintree/address/country_names.rb:5: invalid multibyte char (US-ASCII)
/Users/heli/.rvm/gems/ruby-1.9.2-p0/gems/braintree-2.6.0/lib/braintree/address/country_names.rb:5: invalid multibyte char (US-ASCII)
/Users/heli/.rvm/gems/ruby-1.9.2-p0/gems/braintree-2.6.0/lib/braintree/address/country_names.rb:5: syntax error, unexpected $end, expecting ']'
["Γ…land", "AX", "ALA", "248"],

One solution would be the magic comment:

-- encoding : utf-8 --

I recommend the gem magic_encoding which annotates all source files with the encoding. Personally, I don't agree how Ruby (1.8 and 1.9) handels encodings (actually I think of it more like a bug), but at least using magic comments guarantees that Ruby uses the correct encodings. Hence, I think all Ruby code should use magic comments.

UnexpectedError on update subscription with new payment method token

I'm getting UnexpectedError when tries to update subscription to use another payment method token

       Braintree::Subscription.update(
            'subscription_id', 
            :payment_method_token =>  'a token'
        )

response is an exception

   Braintree::UnexpectedError: Unexpected HTTP_RESPONSE 405>

using
ruby 1.8.7
braintree 2.10.1

How do you turn off standard output for responses?

How do you suppress standard output from appearing in the dots that appear while running specs/tests?

$ rspec
All examples were filtered out; ignoring {:focus=>true}
....................................[Braintree] [04/Apr/2013 17:08:44 UTC] GET /payment_methods/17a2e9313ec0cb1ee62976018ec0cb1e17ad 200
................................................

New release

Any chance of getting a release for the latest commit that resolved the deprecated openssl digest?

Braintree::Customer.find -- NoMethodError: undefined method `strip' for 7290893:Fixnum

There seems to be a bit of inconsistency when it comes to paramater handling here.

When I call Braintree::Customer.find 7290893, I get the an error NoMethodError: undefined method strip' for 7290893:Fixnum`. However if I convert the Fixnum to a String, everything works fine.

Now, the oddity here is that I can pass around a Fixnum customer ID elsewhere without issue. For instance, the following code does not error.

Braintree::CreditCard.create(
  :customer_id => 7290893,
  :number => params[:cc_number],
  :expiration_date => params[:cc_expiration_date],
  :cardholder_name => params[:cc_card_holder_name]
)

Perhaps you can adjust the #find method to allow for Fixnum customer IDs.

WebhookNotification

Hello Team,

When I'm trying to use webhook api, and created a page and using below code πŸ‘

render :text =>Braintree::WebhookNotification.verify(params[:bt_challenge])

Its gives me NameError: uninitialized constant Braintree::WebhookNotification

Do you have any idea on this?

Creating a sample notification with arbitrary values

Hi, I've been trying to test my rails app sending a sample notification with

signature, payload = Braintree::WebhookTesting.sample_notification (      
      Braintree::WebhookNotification::Kind::SubscriptionChargedSuccessfully,
      @subscription.payment_token)
)

post :process_notification, { bt_signature: signature, bt_payload: payload }

The problem is the subscription.transactions field is empty when the notification reaches the controller and is parsed.

Braintree::WebhookNotification.parse(params[:bt_signature], params[:bt_payload]).subscription.transactions.first # => returns nil

Am I doing something wrong or is it a normal behaviour? Is there any way to pass arbitrary values to Braintree::WebhookTesting.sample_notification in order to set values as the transaction field?

Thanks.

POST /transactions/advanced_search 422

A new error has started popping up when running code that has worked for the last few days:

[Braintree] [14/May/2013 16:48:39 UTC] POST /transactions/advanced_search_ids 200
[Braintree] [14/May/2013 16:49:11 UTC] POST /transactions/advanced_search 422
rake aborted!
Unprocessable entity due to an invalid request
/srv/project/shared/bundle/ruby/2.0.0/gems/braintree-2.23.0/lib/braintree/util.rb:4:in `extract_attribute_as_array'
/srv/project/shared/bundle/ruby/2.0.0/gems/braintree-2.23.0/lib/braintree/transaction_gateway.rb:133:in `_fetch_transactions'
/srv/project/shared/bundle/ruby/2.0.0/gems/braintree-2.23.0/lib/braintree/transaction_gateway.rb:70:in `block in search'
/srv/project/shared/bundle/ruby/2.0.0/gems/braintree-2.23.0/lib/braintree/resource_collection.rb:14:in `call'
/srv/project/shared/bundle/ruby/2.0.0/gems/braintree-2.23.0/lib/braintree/resource_collection.rb:14:in `block in each'
/srv/project/shared/bundle/ruby/2.0.0/gems/braintree-2.23.0/lib/braintree/resource_collection.rb:13:in `each'
/srv/project/shared/bundle/ruby/2.0.0/gems/braintree-2.23.0/lib/braintree/resource_collection.rb:13:in `each_slice'
/srv/project/shared/bundle/ruby/2.0.0/gems/braintree-2.23.0/lib/braintree/resource_collection.rb:13:in `each'
transactions = Braintree::Transaction.search do |search|
  search.settled_at <= day.end_of_day
  search.settled_at >= day.beginning_of_day
end
transactions.maximum_size # <-- good! (it's 160)
transactions.first # <-- good!
transactions.first.id # <-- good!

transactions.each { |tran| p tran.id } # <-- bad!

ERROR MESSAGE:
[Braintree] [14/May/2013 16:33:25 UTC] POST /transactions/advanced_search 422
Braintree::UnexpectedError: Unprocessable entity due to an invalid request
from /Users/Alex/.rvm/gems/ruby-1.9.3-p392/gems/braintree-2.21.0/lib/braintree/util.rb:4:in `extract_attribute_as_array'

Including @xgess for notifications.

:cardholder_name should be in Transaction allowed keys

When using Transparent Redirect, you should allow cardholder_name in the info passed to tr_data.

From the docs:

"Any general field may also be included in the tr_data."

But, when you try to do that with a transaction such as {:credit_card => {:cardholder_name => 'test'}} -- it raises an error, saying the key transaction[credit_card][cardholder_name] is invalid.

Simply adding :cardholder_name to the appropriate hash in Transaction#_create_signature works great, and is properly stored on Braintree. See this gist for the patch: https://gist.github.com/367194/8057c98e4cac5a712b9fc167e8bdebeedb5d310d

Support for jruby?

Since there is currently a dependency on libxml-ruby, it is not possible to use this gem for those of us running on jruby. There is now a drop-in replacement for it (libxml-jruby), but I don't know if there is a way for that to be used without forking.

Are there plans to make this gem work in a jruby environment?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.