Skip to content

Commit

Permalink
Merge branch 'master' of github.com:highfidelity/fake_braintree
Browse files Browse the repository at this point in the history
  • Loading branch information
birarda committed Aug 26, 2015
2 parents a83ce97 + 5ef85b0 commit 9c89f51
Show file tree
Hide file tree
Showing 16 changed files with 131 additions and 60 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ of them (yet).
* `Braintree::PaymentMethod.create`
* `Braintree::PaymentMethod.find`
* `Braintree::PaymentMethod.update`
* `Braintree::PaymentMethod.delete`

### Subscription
* `Braintree::Subscription.cancel`
Expand Down
4 changes: 2 additions & 2 deletions asset_versions.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
---
client_version: 2.9.0
dropin_version: 1.7.0
client_version: 2.11.2
dropin_version: 1.8.3

This file was deleted.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ img {
background-repeat: no-repeat;
display: block;
text-indent: -999em;
background-image: url('/dropin/1.7.0/images/1x-s0fcd0a14c6.png');
background-image: url('/dropin/1.8.3/images/1x-s0fcd0a14c6.png');
background-position: 0 0;
height: 28px;
width: 44px; }
@media only screen and (-webkit-min-device-pixel-ratio: 1.5), only screen and (min--moz-device-pixel-ratio: 1.5), only screen and (min-resolution: 240dpi) {
.payment-method-icon.coinbase {
background-image: url('/dropin/1.7.0/images/2x-sf9a66b4f5a.png');
background-image: url('/dropin/1.8.3/images/2x-sf9a66b4f5a.png');
background-position: 0 0;
height: 28px;
width: 44px;
Expand All @@ -101,13 +101,13 @@ img {
background-repeat: no-repeat;
display: block;
text-indent: -999em;
background-image: url('/dropin/1.7.0/images/1x-s0fcd0a14c6.png');
background-image: url('/dropin/1.8.3/images/1x-s0fcd0a14c6.png');
background-position: 0 -72px;
height: 29px;
width: 44px; }
@media only screen and (-webkit-min-device-pixel-ratio: 1.5), only screen and (min--moz-device-pixel-ratio: 1.5), only screen and (min-resolution: 240dpi) {
.payment-method-icon.paypal {
background-image: url('/dropin/1.7.0/images/2x-sf9a66b4f5a.png');
background-image: url('/dropin/1.8.3/images/2x-sf9a66b4f5a.png');
background-position: 0 -212px;
height: 29px;
width: 44px;
Expand All @@ -119,13 +119,13 @@ img {
background-repeat: no-repeat;
display: block;
text-indent: -999em;
background-image: url('/dropin/1.7.0/images/1x-s0fcd0a14c6.png');
background-image: url('/dropin/1.8.3/images/1x-s0fcd0a14c6.png');
background-position: 0 -231px;
height: 28px;
width: 44px; }
@media only screen and (-webkit-min-device-pixel-ratio: 1.5), only screen and (min--moz-device-pixel-ratio: 1.5), only screen and (min-resolution: 240dpi) {
.payment-method-icon.visa {
background-image: url('/dropin/1.7.0/images/2x-sf9a66b4f5a.png');
background-image: url('/dropin/1.8.3/images/2x-sf9a66b4f5a.png');
background-position: 0 -184px;
height: 28px;
width: 44px;
Expand All @@ -137,13 +137,13 @@ img {
background-repeat: no-repeat;
display: block;
text-indent: -999em;
background-image: url('/dropin/1.7.0/images/1x-s0fcd0a14c6.png');
background-image: url('/dropin/1.8.3/images/1x-s0fcd0a14c6.png');
background-position: 0 -203px;
height: 28px;
width: 44px; }
@media only screen and (-webkit-min-device-pixel-ratio: 1.5), only screen and (min--moz-device-pixel-ratio: 1.5), only screen and (min-resolution: 240dpi) {
.payment-method-icon.master-card {
background-image: url('/dropin/1.7.0/images/2x-sf9a66b4f5a.png');
background-image: url('/dropin/1.8.3/images/2x-sf9a66b4f5a.png');
background-position: 0 -128px;
height: 28px;
width: 44px;
Expand All @@ -155,13 +155,13 @@ img {
background-repeat: no-repeat;
display: block;
text-indent: -999em;
background-image: url('/dropin/1.7.0/images/1x-s0fcd0a14c6.png');
background-image: url('/dropin/1.8.3/images/1x-s0fcd0a14c6.png');
background-position: 0 -119px;
height: 28px;
width: 44px; }
@media only screen and (-webkit-min-device-pixel-ratio: 1.5), only screen and (min--moz-device-pixel-ratio: 1.5), only screen and (min-resolution: 240dpi) {
.payment-method-icon.american-express {
background-image: url('/dropin/1.7.0/images/2x-sf9a66b4f5a.png');
background-image: url('/dropin/1.8.3/images/2x-sf9a66b4f5a.png');
background-position: 0 -72px;
height: 28px;
width: 44px;
Expand All @@ -173,13 +173,13 @@ img {
background-repeat: no-repeat;
display: block;
text-indent: -999em;
background-image: url('/dropin/1.7.0/images/1x-s0fcd0a14c6.png');
background-image: url('/dropin/1.8.3/images/1x-s0fcd0a14c6.png');
background-position: 0 -259px;
height: 28px;
width: 44px; }
@media only screen and (-webkit-min-device-pixel-ratio: 1.5), only screen and (min--moz-device-pixel-ratio: 1.5), only screen and (min-resolution: 240dpi) {
.payment-method-icon.diners-club {
background-image: url('/dropin/1.7.0/images/2x-sf9a66b4f5a.png');
background-image: url('/dropin/1.8.3/images/2x-sf9a66b4f5a.png');
background-position: 0 -259px;
height: 28px;
width: 44px;
Expand All @@ -191,13 +191,13 @@ img {
background-repeat: no-repeat;
display: block;
text-indent: -999em;
background-image: url('/dropin/1.7.0/images/1x-s0fcd0a14c6.png');
background-image: url('/dropin/1.8.3/images/1x-s0fcd0a14c6.png');
background-position: 0 -147px;
height: 28px;
width: 44px; }
@media only screen and (-webkit-min-device-pixel-ratio: 1.5), only screen and (min--moz-device-pixel-ratio: 1.5), only screen and (min-resolution: 240dpi) {
.payment-method-icon.maestro {
background-image: url('/dropin/1.7.0/images/2x-sf9a66b4f5a.png');
background-image: url('/dropin/1.8.3/images/2x-sf9a66b4f5a.png');
background-position: 0 -156px;
height: 28px;
width: 44px;
Expand All @@ -209,13 +209,13 @@ img {
background-repeat: no-repeat;
display: block;
text-indent: -999em;
background-image: url('/dropin/1.7.0/images/1x-s0fcd0a14c6.png');
background-image: url('/dropin/1.8.3/images/1x-s0fcd0a14c6.png');
background-position: 0 -287px;
height: 28px;
width: 44px; }
@media only screen and (-webkit-min-device-pixel-ratio: 1.5), only screen and (min--moz-device-pixel-ratio: 1.5), only screen and (min-resolution: 240dpi) {
.payment-method-icon.discover {
background-image: url('/dropin/1.7.0/images/2x-sf9a66b4f5a.png');
background-image: url('/dropin/1.8.3/images/2x-sf9a66b4f5a.png');
background-position: 0 -287px;
height: 28px;
width: 44px;
Expand All @@ -227,13 +227,13 @@ img {
background-repeat: no-repeat;
display: block;
text-indent: -999em;
background-image: url('/dropin/1.7.0/images/1x-s0fcd0a14c6.png');
background-image: url('/dropin/1.8.3/images/1x-s0fcd0a14c6.png');
background-position: 0 -175px;
height: 28px;
width: 44px; }
@media only screen and (-webkit-min-device-pixel-ratio: 1.5), only screen and (min--moz-device-pixel-ratio: 1.5), only screen and (min-resolution: 240dpi) {
.payment-method-icon.jcb {
background-image: url('/dropin/1.7.0/images/2x-sf9a66b4f5a.png');
background-image: url('/dropin/1.8.3/images/2x-sf9a66b4f5a.png');
background-position: 0 -100px;
height: 28px;
width: 44px;
Expand All @@ -249,13 +249,13 @@ img {
background-repeat: no-repeat;
display: block;
text-indent: -999em;
background-image: url('/dropin/1.7.0/images/1x-s0fcd0a14c6.png');
background-image: url('/dropin/1.8.3/images/1x-s0fcd0a14c6.png');
background-position: 0 -343px;
height: 28px;
width: 44px; }
@media only screen and (-webkit-min-device-pixel-ratio: 1.5), only screen and (min--moz-device-pixel-ratio: 1.5), only screen and (min-resolution: 240dpi) {
.cvv-label .payment-method-icon#cvv-icon {
background-image: url('/dropin/1.7.0/images/2x-sf9a66b4f5a.png');
background-image: url('/dropin/1.8.3/images/2x-sf9a66b4f5a.png');
background-position: 0 -343px;
height: 28px;
width: 44px;
Expand All @@ -267,13 +267,13 @@ img {
background-repeat: no-repeat;
display: block;
text-indent: -999em;
background-image: url('/dropin/1.7.0/images/1x-s0fcd0a14c6.png');
background-image: url('/dropin/1.8.3/images/1x-s0fcd0a14c6.png');
background-position: 0 -315px;
height: 28px;
width: 44px; }
@media only screen and (-webkit-min-device-pixel-ratio: 1.5), only screen and (min--moz-device-pixel-ratio: 1.5), only screen and (min-resolution: 240dpi) {
.cvv-label .payment-method-icon#cid-icon {
background-image: url('/dropin/1.7.0/images/2x-sf9a66b4f5a.png');
background-image: url('/dropin/1.8.3/images/2x-sf9a66b4f5a.png');
background-position: 0 -315px;
height: 28px;
width: 44px;
Expand Down Expand Up @@ -2002,14 +2002,14 @@ button#coinbase-container {
background-repeat: no-repeat;
display: block;
text-indent: -999em;
background-image: url('/dropin/1.7.0/images/1x-s0fcd0a14c6.png');
background-image: url('/dropin/1.8.3/images/1x-s0fcd0a14c6.png');
background-position: 0 -421px;
height: 16px;
width: 79px;
margin: 0 auto; }
@media only screen and (-webkit-min-device-pixel-ratio: 1.5), only screen and (min--moz-device-pixel-ratio: 1.5), only screen and (min-resolution: 240dpi) {
button#coinbase-container .coinbase-button-logo {
background-image: url('/dropin/1.7.0/images/2x-sf9a66b4f5a.png');
background-image: url('/dropin/1.8.3/images/2x-sf9a66b4f5a.png');
background-position: 0 -421px;
height: 16px;
width: 79px;
Expand Down Expand Up @@ -2059,15 +2059,15 @@ button.paypal {
background-repeat: no-repeat;
display: block;
text-indent: -999em;
background-image: url('/dropin/1.7.0/images/1x-s0fcd0a14c6.png');
background-image: url('/dropin/1.8.3/images/1x-s0fcd0a14c6.png');
background-position: 0 -399px;
height: 22px;
width: 61px;
display: inline-block;
margin: 8px auto 0; }
@media only screen and (-webkit-min-device-pixel-ratio: 1.5), only screen and (min--moz-device-pixel-ratio: 1.5), only screen and (min-resolution: 240dpi) {
button.paypal .paypal-button-logo {
background-image: url('/dropin/1.7.0/images/2x-sf9a66b4f5a.png');
background-image: url('/dropin/1.8.3/images/2x-sf9a66b4f5a.png');
background-position: 0 -371px;
height: 22px;
width: 61px;
Expand Down Expand Up @@ -4222,7 +4222,7 @@ button.paypal {
background-repeat: no-repeat;
display: block;
text-indent: -999em;
background-image: url('/dropin/1.7.0/images/1x-s0fcd0a14c6.png');
background-image: url('/dropin/1.8.3/images/1x-s0fcd0a14c6.png');
background-position: 0 -101px;
height: 18px;
width: 18px;
Expand All @@ -4231,7 +4231,7 @@ button.paypal {
margin-bottom: -2px; }
@media only screen and (-webkit-min-device-pixel-ratio: 1.5), only screen and (min--moz-device-pixel-ratio: 1.5), only screen and (min-resolution: 240dpi) {
.server-error .error-icon {
background-image: url('/dropin/1.7.0/images/2x-sf9a66b4f5a.png');
background-image: url('/dropin/1.8.3/images/2x-sf9a66b4f5a.png');
background-position: 0 -241px;
height: 18px;
width: 18px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<head>
<title>Cards</title>
<meta charset="UTF-8">
<link href="/dropin/1.7.0/vendor/normalize.css" rel="stylesheet">
<link href="/dropin/1.7.0/braintree-dropin.css" rel="stylesheet">
<script src="/dropin/1.7.0/vendor/modernizr.js"></script>
<link href="/dropin/1.8.3/vendor/normalize.css" rel="stylesheet">
<link href="/dropin/1.8.3/braintree-dropin.css" rel="stylesheet">
<script src="/dropin/1.8.3/vendor/modernizr.js"></script>
</head>
<body class="inline-frame is-loading initial-inline-frame-loading">
<div id="container">
Expand Down Expand Up @@ -35,9 +35,9 @@
<button class="cancel-popup-button">Cancel PayPal Login</button>
</div>

<!--[if LT IE 9]><script src="/dropin/1.7.0/vendor/jquery-1.11.0.js"></script><![endif]-->
<!--[if gte IE 9]><!--><script src="/dropin/1.7.0/vendor/jquery-2.1.0.js"></script><!--<![endif]-->
<script src="/dropin/1.7.0/braintree-dropin-internal.min.js"></script>
<!--[if LT IE 9]><script src="/dropin/1.8.3/vendor/jquery-1.11.0.js"></script><![endif]-->
<!--[if gte IE 9]><!--><script src="/dropin/1.8.3/vendor/jquery-2.1.0.js"></script><!--<![endif]-->
<script src="/dropin/1.8.3/braintree-dropin-internal.min.js"></script>
<script>
var inlineFrame = new braintree.dropin.InlineFrame.Manager({
container: document.getElementById("container")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
<head>
<title>Modal</title>
<meta charset="UTF-8">
<link href="/dropin/1.7.0/vendor/normalize.css" rel="stylesheet">
<link href="/dropin/1.7.0/braintree-dropin.css" rel="stylesheet">
<script src="/dropin/1.7.0/vendor/modernizr.js"></script>
<link href="/dropin/1.8.3/vendor/normalize.css" rel="stylesheet">
<link href="/dropin/1.8.3/braintree-dropin.css" rel="stylesheet">
<script src="/dropin/1.8.3/vendor/modernizr.js"></script>
</head>
<body class="modal-frame">
<div id="container"></div>
<div class="modal-wrap"></div>
<!--[if LT IE 9]><script src="/dropin/1.7.0/vendor/jquery-1.11.0.js"></script><![endif]-->
<!--[if gte IE 9]><!--><script src="/dropin/1.7.0/vendor/jquery-2.1.0.js"></script><!--<![endif]-->
<script src="/dropin/1.7.0/braintree-dropin-internal.min.js"></script>
<!--[if LT IE 9]><script src="/dropin/1.8.3/vendor/jquery-1.11.0.js"></script><![endif]-->
<!--[if gte IE 9]><!--><script src="/dropin/1.8.3/vendor/jquery-2.1.0.js"></script><!--<![endif]-->
<script src="/dropin/1.8.3/braintree-dropin-internal.min.js"></script>
<script>
var modalFrame = new braintree.dropin.ModalFrame({
container: document.getElementById("container")
Expand Down
15 changes: 15 additions & 0 deletions lib/fake_braintree/customer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ def create
if invalid?
response_for_invalid_card
else
load_payment_method!(
@customer_hash.delete('payment_method_nonce'),
@customer_hash['credit_card'] ||= {}
)
credit_cards = customer_hash['credit_cards']
create_customer_with(customer_hash)
credit_cards.each { |card| add_credit_card_to_registry(card) }
Expand Down Expand Up @@ -118,6 +122,11 @@ def set_default_credit_card(credit_card_hash)

def generate_credit_cards_from(new_credit_card_hash)
if new_credit_card_hash.present? && new_credit_card_hash.is_a?(Hash)
load_payment_method!(
new_credit_card_hash.delete('payment_method_nonce'),
new_credit_card_hash
)

new_credit_card_hash['bin'] = new_credit_card_hash['number'][0..5]
new_credit_card_hash['last_4'] = new_credit_card_hash['number'][-4..-1]
new_credit_card_hash['token'] = credit_card_token(new_credit_card_hash)
Expand Down Expand Up @@ -199,5 +208,11 @@ def set_customer_id
def credit_card_token(credit_card_hash_without_token)
md5("#{credit_card_hash_without_token['number']}#{@customer_hash['merchant_id']}")
end

def load_payment_method!(nonce, credit_card_hash)
return unless nonce
payment_method_hash = FakeBraintree.registry.payment_methods[nonce]
credit_card_hash.merge!(payment_method_hash)
end
end
end
11 changes: 10 additions & 1 deletion lib/fake_braintree/sinatra_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,14 @@ def hash_from_request_body_with_key(key)
CreditCard.new(updates, options).update
end

# Braintree::PaymentMethod.delete
delete '/merchants/:merchant_id/payment_methods/any/:credit_card_token' do
cc_hash = {}
options = {token: params[:credit_card_token], merchant_id: params[:merchant_id]}

CreditCard.new(cc_hash, options).delete
end

# Braintree::CreditCard.delete
delete '/merchants/:merchant_id/payment_methods/credit_card/:credit_card_token' do
cc_hash = {}
Expand All @@ -205,7 +213,8 @@ def hash_from_request_body_with_key(key)
else
payment_method_hash = hash_from_request_body_with_key('payment_method')
nonce = payment_method_hash.delete('payment_method_nonce')
FakeBraintree.registry.payment_methods[nonce].merge(payment_method_hash)
h = FakeBraintree.registry.payment_methods
h[nonce] = (h[nonce] || {}).merge(payment_method_hash)
end
options = {merchant_id: params[:merchant_id]}

Expand Down
10 changes: 5 additions & 5 deletions spec/dummy/public/braintree.js

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions spec/fake_braintree/customer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,32 @@
expect(result).to be_success
end

it 'creates a credit card from payment method nonce in credit card hash' do
nonce = FakeBraintree::PaymentMethod.tokenize_card({
number: TEST_CC_NUMBER,
expiration_date: '04/2016'
})
result = Braintree::Customer.create(
credit_card: { payment_method_nonce: nonce }
)

credit_cards = Braintree::Customer.find(result.customer.id).credit_cards
expect(credit_cards.size).to eq 1
expect(credit_cards.first.expiration_date).to eq '04/2016'
end

it 'creates a credit card from payment method nonce' do
nonce = FakeBraintree::PaymentMethod.tokenize_card({
number: TEST_CC_NUMBER,
expiration_date: '04/2016'
})
result = Braintree::Customer.create('payment_method_nonce' => nonce)

credit_cards = Braintree::Customer.find(result.customer.id).credit_cards
expect(credit_cards.size).to eq 1
expect(credit_cards.first.expiration_date).to eq '04/2016'
end

it 'does not overwrite a passed customer id' do
result = Braintree::Customer.create({ 'id' => '123' })

Expand Down
Loading

0 comments on commit 9c89f51

Please sign in to comment.