Giter VIP home page Giter VIP logo

braintree_php_example's Introduction

Braintree PHP Example

Build Status

An example Braintree integration for PHP.

Setup Instructions

  1. Install composer within the example directory. You can find instructions on how to install composer on composer's site.

  2. Run composer:

    php composer.phar install

    Or if you installed composer globally:

    composer install
  3. 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.

  4. Start the internal PHP server on port 3000:

    php -S localhost:3000 -t public_html

Running Tests

All tests are integration tests. Integration tests make API calls to Braintree and require that you set up your Braintree credentials. You can run this project's integration tests by adding your sandbox API credentials to .env and running ./vendor/bin/phpunit --testsuite integration on the command line.

Testing Transactions

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

Pro Tips

  • Run php -S 0.0.0.0:3000 -t public_html when launching the internal PHP server to listen on all interfaces on port 3000.

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_php_example's People

Contributors

aandolg avatar bluk avatar braintreeps avatar crookedneighbor avatar danakatz avatar dayallnash avatar debrado avatar epreuve avatar evanhahn avatar hollabaq86 avatar jdlc avatar jferm avatar kexline4710 avatar lilaconlee avatar mtmarsh3 avatar omgrr avatar pblesi avatar phannam1412 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  avatar  avatar  avatar  avatar  avatar  avatar

braintree_php_example's Issues

paypal onPaymentMethodReceived

with this example both CC and payapal are presented in the dropin, when using credit card the form can be submitted with this method...
// Add the nonce to the form and submit
document.querySelector('#nonce').value = payload.nonce;
form.submit();

When using paypal, user is presented with the green tick once they have completed the paypal payment, but how can the form then be auto submitted, I read of onPaymentMethodReceived() but where to add this?

this didn't work either

onApprove: function (data, actions) {
return paypalCheckoutInstance.tokenizePayment(data, function (err, payload) {
// Submit 'payload.nonce' to your server
});
},

3D secure missing

This php example works great, however it is missing the now required 3D secure support, it would be useful if you added this to the example.
Can you add this request please?

production transaction error at Uncaught exception 'Braintree\Exception\Authorization

General information

  • Environment: Production
  • Language, language version, and OS: PHP SDK on Godaddy Server
    As i tested it on sandbox its working fine but when i was going to test it on production i got this error.

Fatal error: Uncaught exception 'Braintree\Exception\Authorization' in bt-new/vendor/braintree/braintree_php/lib/Braintree/Util.php:59 Stack trace: #0 bt-new/vendor/braintree/braintree_php/lib/Braintree/Http.php(50): Braintree\Util::throwStatusCodeException(403) #1 /bt-new/vendor/braintree/braintree_php/lib/Braintree/TransactionGateway.php(489): Braintree\Http->post('/merchants/jbdd...', Array) #2 /bt-new/vendor/braintree/braintree_php/lib/Braintree/TransactionGateway.php(48): Braintree\TransactionGateway->_doCreate('/transactions', Array) #3 /bt-new/vendor/braintree/braintree_php/lib/Braintree/TransactionGateway.php(300): Braintree\TransactionGateway->create(Array) #4 /bt-new/public_html/checkout.php(123): Braintree\TransactionGateway->sale(Array) #5 {main} thrown in/bt-new/vendor/braintree/braintree_php/lib/Braintree/Util.php on line 59

file missing

General information

  • Environment: this issue in Sandbox
  • Language, language version, and OS:
    *Failed opening required '../vendor/autoload.php' (include_path='.:/usr/share/php') in /var/www/braintree/includes/braintree_init.php

Issue description

require_once(): Failed opening required '../vendor/autoload.php' (include_path='.:/usr/share/php') in /var/www/braintree/includes/braintree_init.php on line 3

Payment method nonce represents an un-vaulted payment instrument

General information

  • Environment: Sandbox
  • Language, language version, and OS: PHP 7.2 on Debian 10

Issue description

Hello, I'm trying to create a Braintree_Subscription using the nonce I'm getting from the client-side dropin, this is my code:

	public function process(Request $request) {
		$payload = $request->payload;
		$nonce = $payload['nonce'];

		$status = Braintree_Subscription::create([
			'paymentMethodNonce' => $nonce,
			'planId' => 'solo',
		]);

		return response()->json([
			'data' => $status,
		]);
	}

But Briantree responds with message: "Payment method nonce represents an un-vaulted payment instrument."
The Drop-in config is nothing special, just authorization and container keys are set.

What am I doing wrong here?

PHP 7.2 "Choose a way to pay" box is missing on index.php

General information

  • Environment: Sandbox
  • Language, language version, and OS: PHP 7.2 running on macOS High Sierra 10.13.3

Issue description

I followed the Setup Instructions in README.md 1-4 and am successfully presented with "Hi, Let's test a transaction" index.php page. However, there is only an Amount box (default $10) ("Choose a way to pay" box is missing). Clicking 'Test Transaction' gives the error

Error: 91508: Cannot determine payment method.

Screenshot with PHP 7.2:
screen shot 2018-04-02 at 4 04 17 pm

Downgrading to PHP <7.2 successfully shows the "Choose a way to pay" box below the Amount box.

Screenshot with PHP 7.1.14:
screen shot 2018-04-02 at 4 03 43 pm

Additional information:

When I am running the internal PHP server with PHP 7.2, it keeps throwing:

PHP Deprecated: Function create_function() is deprecated in /Users/projects/braintree_php_example/vendor/braintree/braintree_php/lib/Braintree/Util.php on line 203

Temporary proposed solution

We could update composer.json from:

  "require" : {
   ...
    "php": ">=5.2.1",
   ...
  },

to:

  "require" : {
   ...
    "php": ">=5.2.1 <7.2",
   ...
  },

Hope this makes sense!

  • Dan

Drop-In ui: How to pre-select a payment method based on a vaulted payment method token?

General information

  • Environment:
    Sandbox but functionality desired for Production as well
  • Language, language version, and OS:
    Latest PHP SDK (integrated with magento via Braintree module)

Issue description

I've read through and researched this topic in depth without finding a clear answer in braintree official docs or elsewhere.

The scenario is as follows:
Before the braintree PayPalCheckout js component is loaded, in our system we already have a saved vaulted payment method token. When the Drop-In ui loads, after customer logs into their PayPal account we want the payment method associated with the saved token to be already selected.

How to do this?
Any help would be greatly appreciated.

Is it possible for result success to be true and transaction to be null ?

checkout.php

if ($result->success || !is_null($result->transaction)) {
    $transaction = $result->transaction;
    header("Location: transaction.php?id=" . $transaction->id);
}

I encountered an issue where the result was true and result transaction is empty in production server and it only happens once in awhile.

No payment nonce available with PayPal

General information

  • Environment: sandbox
  • Language, language version, and OS: PHP 5.6.3 on macOS 10.12.6

Issue description

A payment nonce is not created when adding PayPal as a payment method, despite a payment nonce being created when adding a credit card. Screenshots attached showing the browser console output. I forked this repo to add the console.log and comment out the form submit, which you can see at: ShaunDychko@2e44152.

How do you explain the lack of a payment nonce with PayPal? Am I missing something, or otherwise this means the Drop-in UI in it's current version isn't supporting PayPal?

braintree-paypal-no-nonce

braintree-credit-card-nonce

Missing autoload.php

It seems that the index.php file is looking for the "require 'vendor/autoload.php';" file, but it is not available in the ZIP, thus I cannot get the script to work?

Undefined index: payment_method_nonce

I am working with this example but I get the following error:

Notice: Undefined index: payment_method_nonce in /home/u726770184/public_html/checkout.php on line 5

Fatal error: Uncaught exception 'Braintree\Exception\Authentication' in /home/u726770184/vendor/braintree/braintree_php/lib/Braintree/Util.php:57 Stack trace: #0 /home/u726770184/vendor/braintree/braintree_php/lib/Braintree/Http.php(47): Braintree\Util::throwStatusCodeException(401) #1 /home/u726770184/vendor/braintree/braintree_php/lib/Braintree/TransactionGateway.php(412): Braintree\Http->post('/merchants/vvpf...', Array) #2 /home/u726770184/vendor/braintree/braintree_php/lib/Braintree/TransactionGateway.php(49): Braintree\TransactionGateway->_doCreate('/transactions', Array) #3 /home/u726770184/vendor/braintree/braintree_php/lib/Braintree/TransactionGateway.php(251): Braintree\TransactionGateway->create(Array) #4 /home/u726770184/vendor/braintree/braintree_php/lib/Braintree/Transaction.php(480): Braintree\TransactionGateway->sale(Array) #5 /home/u726770184/public_html/checkout.php(13): Braintree\Transaction::sale(Array) #6 {main} thrown in /home/u726770184/vendor/braintree/braintree_php/lib/Braintree/Util.php on line 57

I don't know what is the problem. Can you help me?. I would be very grateful.

Drop In Request Exception

{com.example.mobileapps.paypaltest V/braintreeEror: com.braintreepayments.api.exceptions.ConfigurationException: Request for configuration has failed: Unable to resolve host "api.sandbox.braintreegateway.com": No address associated with hostname. Future requests will retry up to 3 times}

whats wrong?

Could not open input file: composer.phar

I have already download composer version 1.3.1 in C:\wamp\bin\php\php5.4.12\php.exe and trying to run composer by insert this command "php composer.phar install" in command prompt and output is "Could not open input file: composer.phar"

C:\wamp\www\braintree_php_example-master>php composer.phar install
Could not open input file: composer.phar

Integrate recurring subscription

General information

  • Environment: Sandbox
  • Language, language version, and OS: PHP and js on a Windows Xampp server.

Issue description

See below.

Error 404

Hello,

I have an error 404 after submitting the form (credit card, the expiration date and the amount).

Can you help me please ?

Thanks in advance.

Something went wrong on our end.

General information

  • Environment: 1.30.0

Issue description

it shows Something went wrong on our end. when trying to pay with PayPal.

let me know any configuration issue in my end

Blockchain

General information

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

Issue description

Braintree returns "processor_declined"

I am testing the implementation with a browser and I have this message every time. The Braintree api response returns "processor_declined" and doesn't show information about the token:
imagen

Integrating payment in an existent php application

Iā€™m trying to integrate the payment system in a Wordpress theme. So far, so good - we developed everything and on the local sandbox server (localhost:3000) it all works fine.

My question is:

How should eveything work when iā€™m going to integrate this in a Wordpress theme, on a shared hosting, how should the server be started? Is this possible? Should i simply use the files in public_html?

Thanks in advance!

Integration Error: Detected a 3DS 1.0 Form POST to a 3DS 2.0 Endpoint

General information

  • Environment: Sandbox
  • Language, language version, and OS: PHP 7.3 on Ubuntu 18.10

Issue description

When I activate the 3DSecure, I've got a popup on screen with the error
Integration Error: Detected a 3DS 1.0 Form POST to a 3DS 2.0 Endpoint

You have to use this credit cart number : 4000000000001091

Can you help me please?

Thank you.

Provided code example for detecting successful transactions is misleading

General information

The example here suggests that this is how you check for a successful transaction, doubly so since the else case demonstrates handling an unsuccessful one:

if ($result->success || !is_null($result->transaction)) {
    $transaction = $result->transaction;
    header("Location: " . $baseUrl . "transaction.php?id=" . $transaction->id);
} else {
    $errorString = "";

    foreach($result->errors->deepAll() as $error) {
        $errorString .= 'Error: ' . $error->code . ": " . $error->message . "\n";
    }

    $_SESSION["errors"] = $errorString;
    header("Location: " . $baseUrl . "index.php");
}

However, this is not true. This check will succeed even for failed transactions because it's not obvious that a failed request will still contain a transaction object, even though the docs say that the transaction object is

Returned directly or within a successful result object

the implication being that it will not be returned in an unsuccessful one.

Basing our code on this misleading example has caused us actual financial losses, so I really recommend that you present this differently. For example starting with:

if ($result->success && $result->transaction) {

would detect a successful transaction (as far as I can make out from your docs), and other result combinations could be handled appropriately.

Handle multiple "Merchant ID Accounts"

My braintree account contains 2 Merchant ID Accounts, one for EUR currency and another one for USD currency.
The SDK doesn't offer me a way to mark for which Merchant ID Account the transaction has to be done, and thus select the default which than throws an error because transaction currency doesn't match Merchant ID account currency.

How can I deal with this?

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.