braintree_php_example | An example Braintree integration for PHP | Web Framework library
kandi X-RAY | braintree_php_example Summary
kandi X-RAY | braintree_php_example Summary
An example Braintree integration for PHP.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of braintree_php_example
braintree_php_example Key Features
braintree_php_example Examples and Code Snippets
Community Discussions
Trending Discussions on braintree_php_example
QUESTION
In PHP, I am developing an application that is going to use the Braintree Marketplace functionality - for users within my platform to be able to handle escrow transactions for projects they post. I understand the code on how to do actual transactions, but I am having issues on the sub-merchant process and where that necessary code is supposed to go.
I have looked extensively on how to onboard sub-merchants with the code from their documentation, but where am I supposed to put all this? On its own separate page? The only coding example is the very basics here on Github. I need to be able to create these sub-merchants so that I can test escrow within their Sandbox.
...ANSWER
Answered 2018-Apr-06 at 18:24It turns out that what I was trying to do was a limitation of Braintree itself. At that time, you were not able to test escrow transactions within their Sandbox. Not sure if that has changed over the past year.
For those looking for a much better payments API, check out Stripe instead.
QUESTION
I am creating a web app using PHP/Laravel and Braintree for payments. I am using the Braintree dropin.
A simplified flow of the web app:
- User uploads a file and selects a service from dropdown, submits form
- User is shown quote/price which is calculated by taking the uploaded file's word count * selected service
- User selects payment via Braintree drop-in, submits form to pay
- Web app fires
Braintree_Transaction::sale()
- User is shown success page
Regarding the above, I would like to get some advice on best practice for setting the amount in the Braintree_Transaction::sale()
method call in step 4.
In the Braintree PHP example on github the amount used in the Braintree_Transaction::sale()
method call is taken from a text input in the form, this can be edited by the user, I assume for example purposes.
In my web app flow described above, after step 1, would I be correct to set the quote/price of the selected service in the session then show this value from the session to the user in step 2 and finally pass the value from the session as the amount
to Braintree_Transaction::sale()
? Or is there a different recommended approach to take? My main concern is charging the customer the correct amount.
As the quote/price is calculated in PHP by taking the uploaded file's word count and multiplying it with the service a customer has selected this will at times involve floating point numbers. E.g. Word count is 1000, selected service is proof-reading which is x1.5, so quote would be 1500 => £15.00.
If my memory serves me correctly Stripe represents, for example, one pound (£) in pennies 100
. This is nice as it helps avoid rounding errors. Braintree on the other hand I believe expects one pound (£) to be represented with the decimal point 1.00
.
What would be my best approach to avoid any rounding errors in such a scenario?
Thanks for any suggestions and please ask for more details if required I've tried to make this as brief and general as possible.
...ANSWER
Answered 2017-Mar-10 at 15:59would I be correct to set the quote/price of the selected service in the session then show this value from the session to the user in step 2 and finally pass the value from the session as the amount to Braintree_Transaction::sale()?
Yes, that's one valid approach. Session values are stored server side, so they can't be manipulated directly by the user, and are intended for carrying information across page requests.
Another solution is to store something like a shopping cart in a database. This has the advantages of long term storage so a user could potentially come back to finish the process later, you could easily run reports against it, and you can track things like drop-out rates.
Don't trust the browser with anything except displaying values. Meaning don't store the quote in the browser or perform any calculations there because they can be altered by the user.
What would be my best approach to avoid any rounding errors in such a scenario?
Not enough developers think about this before they get started on a project. If you're not working with integers you need to use fixed point math.
If you are using a relational database, store monetary values as DECIMAL.
Within PHP calculate everything using the bcmath library which properly handles fixed position decimals. It's very simple and keeps numbers in strings. Following your example:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install braintree_php_example
Install composer within the example directory. You can find instructions on how to install composer on composer's site.
Run composer: php composer.phar install Or if you installed composer globally: composer install
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.
Start the internal PHP server on port 3000: php -S localhost:3000 -t public_html
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page