GithubHelp home page GithubHelp logo

braintree / braintree_express_example Goto Github PK

View Code? Open in Web Editor NEW
178.0 72.0 105.0 1.46 MB

An example Braintree integration for Express

License: MIT License

JavaScript 33.67% CSS 60.41% Dockerfile 0.25% Pug 5.65% Procfile 0.02%

braintree_express_example's Introduction

Braintree Express Example

Build Status

An example Braintree integration for Node in the Express framework.

Setup Instructions

  1. Install packages:

    npm install
  2. Copy the contents of example.env into a new file named .env and fill in your Braintree API credentials. Credentials can be found by navigating to Account > My User > View Authorizations in the Braintree Control Panel. Full instructions can be found on our support site.

  3. Start the server:

    npm start

    By default, this runs the app on port 3000. You can configure the port by setting the environmental variable PORT.

Running tests

To run unit tests, use npm run test:unit. These do not require a server and do not make API calls.

To run all tests, run npm test. This requires the server be up (in a separate shell using npm run dev or npm start) to make the relevant API calls to Braintree. npm test requires that your sandbox Braintree credentials be set up as detailed above.

Testing Transactions

Sandbox transactions must be made with sample credit card numbers, and the response of a Transaction.sale() call is dependent on the amount of the transaction.

Help

Disclaimer

This code is provided as is and is only intended to be used for illustration purposes. This code is not production-ready and is not meant to be used in a production environment. This repository is to be used as a tool to help merchants learn how to integrate with Braintree. Any use of this repository or any of its code in a production environment is highly discouraged.

braintree_express_example's People

Contributors

braintreeps avatar c0dr avatar crookedneighbor avatar danakatz avatar debrado avatar dependabot[bot] avatar epreuve avatar evanhahn avatar gesa avatar hollabaq86 avatar kexline4710 avatar lilaconlee avatar matthewarkin avatar mtmarsh3 avatar omgrr avatar pblesi avatar raymondberg avatar sestevens 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

braintree_express_example's Issues

error in connect

gateway = braintree.connect({
^

TypeError: Cannot read property 'connect' of undefined
at Object. (C:\Users\admin\backend-ecommerce\controllers\braintree.js:13:21)
at Module._compile (internal/modules/cjs/loader.js:1156:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
at Module.load (internal/modules/cjs/loader.js:1000:32)
at Function.Module._load (internal/modules/cjs/loader.js:899:14)
at Module.require (internal/modules/cjs/loader.js:1042:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object. (C:\Users\admin\backend-ecommerce\routes\braintree.js:6:43)
at Module._compile (internal/modules/cjs/loader.js:1156:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
at Module.load (internal/modules/cjs/loader.js:1000:32)
at Function.Module._load (internal/modules/cjs/loader.js:899:14)
at Module.require (internal/modules/cjs/loader.js:1042:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object. (C:\Users\admin\backend-ecommerce\app.js:14:25)
at Module._compile (internal/modules/cjs/loader.js:1156:30)

Integrating Braintree

Hi,

I’m trying to implement Braintree server with node.js I’m following the tutorial

And when I reach the nom test I have 3 test failures, -

3 failing

  1. Checkouts show page respond with 200:
    Error: timeout of 2500ms exceeded. Ensure the done() callback is being called in this test.

  2. Checkouts show page displays a failure page when transaction failed:
    Error: timeout of 2500ms exceeded. Ensure the done() callback is being called in this test.

  3. Checkouts create when the transaction is not successful when there are processor errors displays the transaction status:
    Error: timeout of 2500ms exceeded. Ensure the done() callback is being called in this test.

Beside that I’m trying to use my iOS app to send transaction to my server , I see in my log the payment nonce is. Sent to the server but I do not see the transactions in my Dashboard,
My code is pretty much copied from the docs :

class ViewController: UIViewController {

@IBOutlet weak var BUt: UIButton!
var paymentMethod : BTPaymentMethodNonce?
@IBAction func Butapped(_ sender: Any) {
    showDropIn(clientTokenOrTokenizationKey: "sandbox_t45fvztb_245nc5pjv2tyt3n8")
}


override func viewDidLoad() {
    super.viewDidLoad()
    BUt.isUserInteractionEnabled = false
    BUt.backgroundColor = UIColor.red
    fetchClientToken()
    // Do any additional setup after loading the view, typically from a nib.
}


func postNonceToServer(paymentMethodNonce: String) {
    // Update URL with your server
    let paymentURL = URL(string: "http://localhost:3000")!
    var request = URLRequest(url: paymentURL)
    request.httpBody = "payment_method_nonce=\(paymentMethodNonce)".data(using: String.Encoding.utf8)
    request.httpMethod = "POST"
    
    URLSession.shared.dataTask(with: request) { (data, response, error) -> Void in
        // TODO: Handle success or failure
        if let err = error {
            print("\(err.localizedDescription)")
        }
        else {print("success!")}
        }.resume()
}

@IBAction func PayTapped(_ sender: UIButton) {
    let paymentMethodNonce = "fake-valid-nonce"
    postNonceToServer(paymentMethodNonce: paymentMethodNonce)
}

func fetchClientToken() {
    // TODO: Switch this URL to your own authenticated API
    let clientTokenURL = NSURL(string: "http://localhost:3000")!
    let clientTokenRequest = NSMutableURLRequest(url: clientTokenURL as URL)
    clientTokenRequest.setValue("text/plain", forHTTPHeaderField: "Accept")
    
    URLSession.shared.dataTask(with: clientTokenRequest as URLRequest) { (data, response, error) -> Void in
        if let err = error {
            print("\(err.localizedDescription)")
        }
        // TODO: Handle errors
        let clientToken = String(data: data!, encoding: String.Encoding.utf8)
        
        // As an example, you may wish to present Drop-in at this point.
        // Continue to the next section to learn more...
        DispatchQueue.main.async {
            self.BUt.isUserInteractionEnabled = true
            self.BUt.backgroundColor = UIColor.white
        }

        }.resume()
}


func showDropIn(clientTokenOrTokenizationKey: String) {
    let request =  BTDropInRequest()
    let dropIn = BTDropInController(authorization: clientTokenOrTokenizationKey, request: request)
    { (controller, result, error) in
        if (error != nil) {
            print("ERROR")
        } else if (result?.isCancelled == true) {
            print("CANCELLED")
        } else if let result = result {
            // Use the BTDropInResult properties to update your UI
            // result.paymentOptionType
            // result.paymentMethod
            // result.paymentIcon
            // result.paymentDescription
        }
        controller.dismiss(animated: true, completion: nil)
    }
    self.present(dropIn!, animated: true, completion: nil)
}



func alert(message: String, title: String = "") {
    let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
    let OKAction = UIAlertAction(title: "OK", style: .default, handler: nil)
    alertController.addAction(OKAction)
    self.present(alertController, animated: true, completion: nil)
}

}

Please let me know what am I doing wrong.

Thanks .

Scrolling on iOS is sticky

When testing Node JS braintree example on iOS, Safari and Chrome, scrolling vertically is sticky (e.g. I swipe up and the page freezes, I can't scroll all the way to the bottom). When testing on Android or desktop browsers, the scrolling works fine. https://coder-kids.herokuapp.com/checkouts/new

PS. "Submit an issue" link in braintree_express_example re-directs to rails example issue tracker.

Error: 91564: Cannot use a payment_method_nonce more than once.

General information

  • Environment: Sandbox
  • Language, language version, and OS: Node v10.5.0, Windows Version 10.0.17134 Build 17134

Issue description

  1. npm i
  2. get .env file setup
  3. npm start
  4. Try to create a transaction with your card only to realize you have to setup an account in the braintree dashboard
  5. create account in braintree dashboard
  6. make purchase and receive error

TypeError: Cannot read property 'charAt' of undefined

Run the code as per the document and got the error below

[email protected] start /home/gaz/Downloads/braintree_express_example-master

node ./bin/www

/home/gaz/Downloads/braintree_express_example-master/lib/gateway.js:7
environment = process.env.BT_ENVIRONMENT.charAt(0).toUpperCase() + process.env.BT_ENVIRONMENT.slice(1);
^

TypeError: Cannot read property 'charAt' of undefined
at Object. (/home/gaz/Downloads/braintree_express_example-master/lib/gateway.js:7:42)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:643:32)
at Function.Module._load (internal/modules/cjs/loader.js:556:12)
at Module.require (internal/modules/cjs/loader.js:683:19)
at require (internal/modules/cjs/helpers.js:16:16)
at Object. (/home/gaz/Downloads/braintree_express_example-master/routes/index.js:6:15)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: node ./bin/www
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /home/gaz/.npm/_logs/2019-07-23T06_13_37_916Z-debug.log

Debit card issues

General information

I am not able to get the venmo app to accept any of my debit cards.

  • Environment:
  • Language, language version, and OS:

Issue description

Total meltdown

npm test, error!

Cannot find module 'eslint-config-braintree/server'
Referenced from: /Users/mac/Desktop/braintree_express_example/.eslintrc
Error: Cannot find module 'eslint-config-braintree/server'
Referenced from: /Users/mac/Desktop/braintree_express_example/.eslintrc
at ModuleResolver.resolve (/usr/local/lib/node_modules/eslint/lib/util/module-resolver.js:74:19)
at resolve (/usr/local/lib/node_modules/eslint/lib/config/config-file.js:515:25)
at load (/usr/local/lib/node_modules/eslint/lib/config/config-file.js:584:26)
at configExtends.reduceRight (/usr/local/lib/node_modules/eslint/lib/config/config-file.js:421:36)
at Array.reduceRight ()
at applyExtends (/usr/local/lib/node_modules/eslint/lib/config/config-file.js:403:28)
at loadFromDisk (/usr/local/lib/node_modules/eslint/lib/config/config-file.js:556:22)
at Object.load (/usr/local/lib/node_modules/eslint/lib/config/config-file.js:592:20)
at Config.getLocalConfigHierarchy (/usr/local/lib/node_modules/eslint/lib/config.js:228:44)
at Config.getConfigHierarchy (/usr/local/lib/node_modules/eslint/lib/config.js:182:43)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] lint: eslint .
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] lint script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /Users/mac/.npm/_logs/2017-09-16T00_26_36_428Z-debug.log
npm ERR! Test failed. See above for more details.

npm install eslint-config-braintree --save 

Or error

npm start error!

[email protected] start /Users/mac/Desktop/braintree_express_example
node ./bin/www

{ Error: ENOENT: no such file or directory, open '.env'
at Object.fs.openSync (fs.js:652:18)
at Object.fs.readFileSync (fs.js:553:33)
at Object.config (/Users/mac/Desktop/braintree_express_example/node_modules/dotenv/lib/main.js:30:37)
at Object. (/Users/mac/Desktop/braintree_express_example/lib/gateway.js:6:19)
at Module._compile (module.js:573:30)
at Object.Module._extensions..js (module.js:584:10)
at Module.load (module.js:507:32)
at tryModuleLoad (module.js:470:12)
at Function.Module._load (module.js:462:3)
at Module.require (module.js:517:17) errno: -2, code: 'ENOENT', syscall: 'open', path: '.env' }
/Users/mac/Desktop/braintree_express_example/lib/gateway.js:7
environment = process.env.BT_ENVIRONMENT.charAt(0).toUpperCase() + process.env.BT_ENVIRONMENT.slice(1);
^

TypeError: Cannot read property 'charAt' of undefined
at Object. (/Users/mac/Desktop/braintree_express_example/lib/gateway.js:7:41)
at Module._compile (module.js:573:30)
at Object.Module._extensions..js (module.js:584:10)
at Module.load (module.js:507:32)
at tryModuleLoad (module.js:470:12)
at Function.Module._load (module.js:462:3)
at Module.require (module.js:517:17)
at require (internal/module.js:11:18)
at Object. (/Users/mac/Desktop/braintree_express_example/routes/index.js:6:15)
at Module._compile (module.js:573:30)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: node ./bin/www
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /Users/mac/.npm/_logs/2017-09-16T00_30_01_208Z-debug.log

Deploy to heroku error

General information

  • Environment: Sandbox
  • Language, language version, and OS: Default Heroku deployment

Issue description

Deploying app to Heroku by clicking on the "Deploy to Heroku" gives the following error

An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details. You can do this from the Heroku CLI with the command

The logs show the following

2020-08-16T20:08:09.643994+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=slay-inc.herokuapp.com request_id=9bd19aaf-5060-46a1-ad2e-674fcb4b7e25 fwd="112.135.239.111" dyno= connect= service= status=503 bytes= protocol=https
2020-08-16T20:08:10.378525+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=slay-inc.herokuapp.com request_id=ed1f6a68-491c-4dbf-953b-eb822fa0a59e fwd="112.135.239.111" dyno= connect= service= status=503 bytes= protocol=https

Demo.js

General information

  • Environment: Sandbox
  • Language, language version, and OS: Mac, Node etc.

Issue description

I would like to query Demo.js and the need to include it in this example. I've had a look through the code and I believe it adds a few very small UI mods to the form - is it worth it? Could you update the docs to say what it does or remove it for brevity.

clientToken issue

I get this output in conosole when i try to load the app in my browser:

TypeError: Cannot read property 'clientToken' of undefined
at /Users/deni/Downloads/braintree_express_example-master/routes/index.js:57:56
at Timeout._onTimeout (/Users/deni/Downloads/braintree_express_example-master/node_modules/@braintree/wrap-promise/lib/deferred.js:10:12)
at ontimeout (timers.js:436:11)
at tryOnTimeout (timers.js:300:5)
at listOnTimeout (timers.js:263:5)
at Timer.processTimers (timers.js:223:10)

Unable to checkout in sandbox

General information

  • Environment: =Sandbox
  • Language, language version, and OS: Node v7.10.1 on Ubuntu 14.10

Issue description

When I open "http://localhost:3000/checkouts/new" and try to click on "Test Transaction", I got following error in console.

Uncaught TypeError: Cannot read property 'requestPaymentMethod' of undefined at HTMLFormElement.<anonymous> (new:14)

I am not getting any error logs in console.

Amount

var amount = req.body.amount; // In production you should not take amounts directly from clients

In this line, you are talking about not using it in production. But how we should do it?
How can I add to the pay-method-nonce sent by the client to the server the agreed price, so the server can not modify it?

Tanks you.

npm start error out and stopped

General information

  • Environment: sandobx
  • Language, language version, and OS:

node v8.9.1

Issue description

after npm install, it just error out when npm start

screen shot 2018-08-01 at 6 18 04 am

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.