{"id":15048283,"url":"https://github.com/github/fake_braintree","last_synced_at":"2025-10-04T08:31:16.251Z","repository":{"id":26192585,"uuid":"29638616","full_name":"github/fake_braintree","owner":"github","description":"A Braintree so fake that you can avoid hitting Braintree servers in tests.","archived":true,"fork":true,"pushed_at":"2017-10-17T19:02:25.000Z","size":323,"stargazers_count":8,"open_issues_count":0,"forks_count":7,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-09-29T00:21:23.626Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"highfidelity/fake_braintree","license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/github.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-01-22T01:27:29.000Z","updated_at":"2024-07-31T03:19:32.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/github/fake_braintree","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/github%2Ffake_braintree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/github%2Ffake_braintree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/github%2Ffake_braintree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/github%2Ffake_braintree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/github","download_url":"https://codeload.github.com/github/fake_braintree/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235232479,"owners_count":18957057,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-09-24T21:10:16.373Z","updated_at":"2025-10-04T08:31:10.926Z","avatar_url":"https://github.com/github.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fake\\_braintree, a Braintree fake [![Build Status](https://secure.travis-ci.org/thoughtbot/fake_braintree.png)](http://travis-ci.org/thoughtbot/fake_braintree)\n\n\nThis library is a way to test [Braintree](http://www.braintreepayments.com/)\ncode without hitting Braintree's servers. It uses\n[Capybara::Server](https://github.com/jnicklas/capybara/blob/master/lib/capybara/server.rb)\nto intercept all of the calls from Braintree's Ruby library and returns XML that\nthe Braintree library can parse. The whole point is not to hit the Braintree\nAPI.\n\nIt supports a lot of Braintree methods, but it does not support every single one\nof them (yet).\n\n## Supported API methods\n\n### Address\n* `Braintree::Address.create`\n\n### CreditCard\n* `Braintree::CreditCard.create`\n* `Braintree::CreditCard.find`\n* `Braintree::CreditCard.sale`\n* `Braintree::CreditCard.update`\n\n### Customer\n* `Braintree::Customer.create` (including adding add-ons and discounts)\n* `Braintree::Customer.delete`\n* `Braintree::Customer.find`\n* `Braintree::Customer.update`\n\n### Subscription\n* `Braintree::Subscription.cancel`\n* `Braintree::Subscription.create`\n* `Braintree::Subscription.find`\n* `Braintree::Subscription.update`\n* `Braintree::Subscription.retry_charge`\n\n### Transaction\n* `Braintree::Transaction.find`\n* `Braintree::Transaction.refund`\n* `Braintree::Transaction.sale`\n* `Braintree::Transaction.void`\n* `Braintree::Transaction.submit_for_settlement`\n\n### TransparentRedirect\n* `Braintree::TransparentRedirect.confirm` (only for creating customers)\n* `Braintree::TransparentRedirect.url`\n\n## Quick start\nRequire the library and activate it to start the API server:\n\n    require 'fake_braintree'\n    FakeBraintree.activate!\n\nTo run the server on a specific port, pass in the `:gateway_port` option:\n\n    FakeBraintree.activate!(gateway_port: 1234)\n\n`FakeBraintree.clear!` will clear all data, which you almost certainly want to\ndo before each test.\n\nFull example:\n\n    # spec/spec_helper.rb\n    require 'fake_braintree'\n    FakeBraintree.activate!\n\n    RSpec.configure do |c|\n      c.before do\n        FakeBraintree.clear!\n      end\n    end\n\nIf you're using Cucumber, add this too:\n\n    # features/support/env.rb\n    require 'fake_braintree'\n    FakeBraintree.activate!\n\n    Before do\n      FakeBraintree.clear!\n    end\n\nIt is advised to run your tests with `js: true` (RSpec) or `@javascript`\n(Cucumber), so that the requests correctly go through `FakeBraintree`. You might\nwant to take a look at\n[capybara-webkit](https://github.com/thoughtbot/capybara-webkit).\n\n## Don't set the Braintree environment\n\n`fake_braintree` sets `Braintree::Configuration.environment = :development`. If\nyour code sets it to anything else (like `:sandbox`), then `fake_braintree` won't\nwork.\n\n# Credit Cards\n\n* `credit_card.card_type` will always be `\"FakeBraintree\"`.\n\n## Verifying credit cards\n\nTo verify every credit card you try to use, call:\n\n    FakeBraintree.verify_all_cards!\n\nThis will stay \"on\" until you set\n\n    FakeBraintree.verify_all_cards = false\n\nCalling `FakeBraintree.clear!` _will not_ change this setting. It does very basic\nverification: it only matches the credit card number against these:\nhttp://www.braintreepayments.com/docs/ruby/reference/sandbox and rejects them if\nthey aren't one of the listed numbers.\n\n## Declining credit cards\n\nTo decline every card you try, call:\n\n    FakeBraintree.decline_all_cards!\n\nThis will decline all cards until you call\n\n    FakeBraintree.clear!\n\nThis behavior is different from `FakeBraintree.verify_all_cards`, which will\nstay on even when `clear!` is called.\n\nNote that after `decline_all_cards!` is set, Braintree will still create\ncustomers, but will not be able to charge them (so charging for e.g. a subscription\nwill fail). Setting `verify_all_cards!`, on the other hand, will prevent\ncreation of customers with bad credit cards - Braintree won't even get to trying\nto charge them.\n\n## Generating transactions\n\nYou can generate a transaction using `FakeBraintree.generate_transaction`. This\nis for use in testing, e.g.\n`before { user.transaction = FakeBraintree.generate_transaction }`.\n\nIt takes the following options:\n\n* `:subscription_id`: the ID of the subscription associated with the transaction.\n* `:created_at`: when the transaction was created (defaults to `Time.now`)\n* `:amount`: the amount of the transaction\n* `:status`: the status of the transaction, e.g. `Braintree::Transaction::Status::Failed`\n\nAny or all of these can be nil, and in fact are nil by default. You can also\ncall it with no arguments.\n\nFull example:\n\n    transaction = FakeBraintree.generate_transaction(\n      amount: '20.00',\n      status: Braintree::Transaction::Status::Settled,\n      subscription_id: 'foobar',\n      created_at: Time.now + 60\n    )\n\n    p transaction\n    # {\n    #   \"status_history\" =\u003e\n    #     [{\n    #       \"timestamp\"  =\u003e 2011-11-20 12:57:25 -0500,\n    #       \"amount\"     =\u003e \"20.00\",\n    #       \"status\"     =\u003e \"settled\",\n    #       \"created_at\" =\u003e 2011-11-20 12:58:25 -0500\n    #     }],\n    #   \"subscription_id\" =\u003e \"foobar\"\n    # }\n\nNote that the generated transaction is not saved in `fake_braintree` - the\nmethod just gives you a hash.\n\n## Adding your own transactions\n\nIf you want `fake_braintree` to be aware of a transaction, you can add it to the\n`FakeBraintree.registry.transactions` hash like this:\n\n\n```ruby\ntransaction_id = \"something\"\nexample_response = { \"id\" =\u003e transaction_id, \"amount\" =\u003e \"10.0\", \"type\" =\u003e \"credit\", \"status\" =\u003e \"authorized\" }\nFakeBraintree.registry.transactions[transaction_id] = example_response\n```\n\nNow you can do `Braintree::Transaction.find(\"something\")` and it will find that\ntransaction.\n\nNot all of the keys in `example_response` are necessary, but you'll probably\nwant at least `id` and `amount`, depending on the type of response.\n\n`FakeBraintree.registry.transactions` will be cleared when you call\n`FakeBraintree.clear!`.\n\n\n## Running the tests\n\nDuring tests, debug-level logs will be sent to `tmp/braintree_log`. This is\nuseful for seeing which URLs Braintree is actually hitting.\n\nCredits\n-------\n\n![thoughtbot](http://thoughtbot.com/images/tm/logo.png)\n\nFake Braintree is maintained and funded by [thoughtbot, inc](http://thoughtbot.com/community)\n\nThank you to all [the contributors](https://github.com/thoughtbot/fake_braintree/contributors)!\n\nThe names and logos for thoughtbot are trademarks of thoughtbot, inc.\n\nLicense\n-------\n\nFake Braintree is Copyright © 2011-2013 thoughtbot. It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgithub%2Ffake_braintree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgithub%2Ffake_braintree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgithub%2Ffake_braintree/lists"}