Skip to content

Commit

Permalink
Allow credit cards to be specified as month/year instead of date
Browse files Browse the repository at this point in the history
  • Loading branch information
jferris committed Nov 15, 2011
1 parent 47d00aa commit 36f2b5e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
7 changes: 4 additions & 3 deletions lib/fake_braintree/customer.rb
Expand Up @@ -30,9 +30,10 @@ def customer_hash
if !hash["credit_card"].empty?
hash["credit_card"]["last_4"] = hash["credit_card"].delete("number")[-4..-1]
hash["credit_card"]["token"] = md5("#{hash['merchant_id']}#{hash['id']}")
expiration_date = hash["credit_card"].delete("expiration_date")
hash["credit_card"]["expiration_month"] = expiration_date.split('/')[0]
hash["credit_card"]["expiration_year"] = expiration_date.split('/')[1]
if expiration_date = hash["credit_card"].delete("expiration_date")
hash["credit_card"]["expiration_month"] = expiration_date.split('/')[0]
hash["credit_card"]["expiration_year"] = expiration_date.split('/')[1]
end

credit_card = hash.delete("credit_card")
hash["credit_cards"] = [credit_card]
Expand Down
11 changes: 10 additions & 1 deletion spec/fake_braintree/customer_spec.rb
@@ -1,7 +1,9 @@
require 'spec_helper'

describe "Braintree::Customer.create" do
let(:expiration_date) { "04/2016" }
let(:expiration_month) { "04" }
let(:expiration_year) { "2016" }
let(:expiration_date) { [expiration_month, expiration_year].join("/") }
after { FakeBraintree.verify_all_cards = false }

def create_customer_with_credit_card(options)
Expand All @@ -14,6 +16,13 @@ def create_customer_with_credit_card(options)
result.should be_success
end

it "creates a customer using an expiration month and year" do
result = create_customer_with_credit_card(:number => TEST_CC_NUMBER,
:expiration_month => expiration_month,
:expiration_year => expiration_year)
result.should be_success
end

it "records the billing address" do
result = create_customer_with_credit_card(
:number => TEST_CC_NUMBER,
Expand Down

0 comments on commit 36f2b5e

Please sign in to comment.