Coder Social home page Coder Social logo

omnipay-braintree's Introduction

Omnipay: Braintree

Braintree driver for the Omnipay PHP payment processing library

Build Status Latest Stable Version Total Downloads

Omnipay is a framework agnostic, multi-gateway payment processing library for PHP 7.2+. This package implements Braintree support for Omnipay.

Installation

Omnipay is installed via Composer. To install, simply add it to your composer.json file:

composer require omnipay/braintree:"~4.0@dev"

Basic Usage

The following gateways are provided by this package:

  • Braintree

You need to set your merchantId, publicKey and privateKey. Setting testMode to true will use the sandbox environment.

This gateway supports purchase through a token (payment nonce) only. You can generate a clientToken for Javascript:

$clientToken = $gateway->clientToken()->send()->getToken();

The generated token will come in handy when using the Javascript SDK to display the Drop-in Payment UI or hosted fields used to collect payment method information.

On successful submission of the payment form, a one-time-use token that references a payment method provided by your customer, such as a credit card or PayPal account is dynamically added to the form as the value of a hidden payment_method_nonce input field.

Use the payment_method_nonce to process your customer order like so:

$response = $gateway->purchase([
            'amount' => '10.00',
            'token' => $_POST['payment_method_nonce']
        ])->send();

For general usage instructions, please see the main Omnipay repository.

Driver specific usage

Create customer

$customer = $gateway->createCustomer([
    'customerData' => [
        'id' => 1,
        'firstName' => 'John',
        'lastName' => 'Doe'
    ]
])->send();

You can find full list of options here.

Find customer (By ID)

$customer = $gateway->findCustomer(1)->send();

You can find full list of options here

Create payment method

$method = $gateway->createPaymentMethod([
    'customerId' => $user->getId(),
    'paymentMethodNonce' => 'paymentnonce',
    'options' => [
        'verifyCard' => true
    ]
]);

You can find full list of options here.

Update payment method

$method = $gateway->updatePaymentMethod([
    'paymentMethodToken' => 'token123',
    'options' => [
        'paymentMethodNonce' => 'paymentnonce'
    ]
]);

You can find full list of options here.

Create subscription

$subscription = $gateway->createSubscription([
    'subscriptionData' => [
        'paymentMethodToken' => 'payment_method_token',
        'planId' => 'weekly',
        'price' => '30.00'
    ]
])->send();

You can find full list of options here

Cancel subscription

$subscription = $gateway->cancelSubscription('id')->send();

You can find full list of options here

Parse webhook notification

$notification = $gateway->parseNotification([
    'bt_signature' => 'signature',
    'bt_payload' => 'payload'
])->send();

You can find full list of options here

Support

If you are having general issues with Omnipay, we suggest posting on Stack Overflow. Be sure to add the omnipay tag so it can be easily found.

If you want to keep up to date with release anouncements, discuss ideas for the project, or ask more detailed questions, there is also a mailing list which you can subscribe to.

If you believe you have found a bug, please report it using the GitHub issue tracker, or better yet, fork the library and submit a pull request.

omnipay-braintree's People

Contributors

1ed avatar alexmglover avatar axiomsteve avatar barrycarrjr avatar barryvdh avatar bobbyshaw avatar bryglen avatar delatbabel avatar domis86 avatar drewm avatar greydnls avatar ivanmitrikeski avatar kbussche avatar mambose avatar paulchubatyy avatar ptuchik avatar tariq86 avatar timeverts 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

omnipay-braintree's Issues

Braintree find customer not working

Hi,
i am working on laravel api, integrated omnipay/braintree, i have successfully created my customer, what i need to get customer data through this,
$mycustomer = $omnipay_gateway->findCustomer(5)->send();
but it giving me bad response like,

Omnipay\Braintree\Message\CustomerResponse Object
(
    [request:protected] => Omnipay\Braintree\Message\FindCustomerRequest Object
        (
            [braintree:protected] => Braintree\Gateway Object
                (
                    [config] => Braintree\Configuration Object

its a huge chunck of data which i am not pasting here, how i get my customer details through this type of data, and it shows in this format, why not in proper json or some other format?

$gateway->findCustomer()->send()->getCustomerData() returns null

While the readme isn't clear about what is and what isn't expected behaviour, I landed on the following code to check if a customer id exists:

$id = '...';
$existingCustomer = $this->instance->findCustomer($id)->send();
if ($customer = $existingCustomer->getCustomerData()) {
    return $customer->id;
}

However, getCustomerData() returns null.

This seems to be due the implementation in CustomerResponse, which is looking for $this->data->customer. In the findCustomer request however, the customer object is $this->data (so getData() does get me what I need).

https://github.com/thephpleague/omnipay-braintree/blob/master/src/Message/CustomerResponse.php#L12-L14

(Note I'm on v1.1.2 and currently unable of upgrading to Omnipay 3 due to the PHP requirement, but from a very brief look at the v2 code that doesn't seem to have changed)

What's expected here? Should getCustomerData work in the findCustomer request, or is the documentation that says getData should be used missing?

Missing method in Gateway

The createCard method is not defined or implemented in Gateway, but it is listed as a @method in GatewayInterface. I am using the latest '3.0.x-dev' version. Using the recommended nonce method works perfectly, but I have some cases where I cannot rely on the nonce, and must use card data. I can see there's no CreateCardRequest object, either. Is this on purpose due to the workflow described here: https://stackoverflow.com/a/32131395/1611905 ?

Call to undefined method Omnipay\Braintree\Gateway::merchantId()

I am using Laravel 5.3 with Php 7.*.

Hi,

I am getting below error for the braintree payment gateway integrated in my laravel code. Am I missing some step or anything?

Laravel controller code

$gateway = Omnipay::create('Braintree');

        $gateway->merchantId('merchant_id');
        $gateway->publicKey('public_key');
        $gateway->privateKey('private_key');
        $gateway->testMode('true');
        $clientToken = $gateway->clientToken()->send()->getToken();

        return $clientToken;

Latest AVS Rules support PR breaks transactions without address

When PR #36 was merged in, it broke transactions that do not contain an address. Braintree doesn't require an address for a transaction but it does if you have AVS rules configured.

By default AVS rules are not configured so this can be replicated with a new Braintree sandbox account.

If you try to make a transaction without an address the Braintree API will reject it with the following error...

message=Addresses must have at least one field filled in

For more information on this error see https://developers.braintreepayments.com/reference/general/validation-errors/all/ruby#code-81801

@barrycarrjr

Releases?

Any chance of a release/version tag for this driver? We've been using it in production, and all seems stable enough, so it would be nice to have the comfort of semantic versioning in case there are any braking changes introduced...

Update subscriptions?

I can find response objects for creating and canceling subscriptions, but I can't find anything that ties to update them? Am I missing something or is this feature just not implemented?

Purchase with customer id not working

Following error comes up when trying to charge the customer created previously.

InvalidRequestException in AuthorizeRequest.php line 43:
The token (payment nonce) or paymentMethodToken field should be set.

Everything works fine when i commented the special validations in AuthorizeRequest.php. I don't think payment nonce or paymentMethodToken validation is required when purchasing using customer reference

`$item->getPrice()` being used as a total amount when it is a unit amount

$item->getPrice() returns the item's unit price and not the line item's total amount. This is creating inaccurate line item data when viewing transactions in Braintree.

'totalAmount' => abs($item->getPrice()),
'unitAmount' => abs($unit_amount),

The code should look something like this:

'totalAmount' => abs(round($item->getQuantity() * $item->getPrice(), $this->getCurrencyDecimalPlaces())),
'unitAmount' => abs(round($item->getPrice(), $this->getCurrencyDecimalPlaces())),

fail to install

i unable to composer install, and i can't figure out why, anyone can guide me?

devlim@DEVLIM:~/Desktop/demo$ composer require omnipay/braintree:"~2.0@dev"
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - The requested package omnipay/braintree ~2.0@dev exists as omnipay/braintree[1.0.0, dev-master, 3.0.x-dev, v1.1.0, v1.1.1, v1.1.2] but these are rejected by your constraint.


Installation failed, reverting ./composer.json to its original content.
devlim@DEVLIM:~/Desktop/demo$ composer require omnipay/braintree
Using version ^1.1 for omnipay/braintree
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Conclusion: don't install omnipay/braintree v1.1.2
    - Conclusion: don't install omnipay/braintree v1.1.1
    - Conclusion: remove omnipay/common v3.0.2
    - Installation request for omnipay/braintree ^1.1 -> satisfiable by omnipay/braintree[v1.1.0, v1.1.1, v1.1.2].
    - Conclusion: don't install omnipay/common v3.0.2
    - omnipay/braintree v1.1.0 requires omnipay/common ~2.0 -> satisfiable by omnipay/common[2.3.2, 2.4.0, 2.5.2, 2.5.x-dev, v2.0.0, v2.1.0, v2.2.0, v2.3.0, v2.3.1, v2.3.3, v2.3.4, v2.4.1, v2.5.0, v2.5.1].
    - Can only install one of: omnipay/common[2.3.2, v3.0.2].
    - Can only install one of: omnipay/common[2.4.0, v3.0.2].
    - Can only install one of: omnipay/common[2.5.2, v3.0.2].
    - Can only install one of: omnipay/common[2.5.x-dev, v3.0.2].
    - Can only install one of: omnipay/common[v2.0.0, v3.0.2].
    - Can only install one of: omnipay/common[v2.1.0, v3.0.2].
    - Can only install one of: omnipay/common[v2.2.0, v3.0.2].
    - Can only install one of: omnipay/common[v2.3.0, v3.0.2].
    - Can only install one of: omnipay/common[v2.3.1, v3.0.2].
    - Can only install one of: omnipay/common[v2.3.3, v3.0.2].
    - Can only install one of: omnipay/common[v2.3.4, v3.0.2].
    - Can only install one of: omnipay/common[v2.4.1, v3.0.2].
    - Can only install one of: omnipay/common[v2.5.0, v3.0.2].
    - Can only install one of: omnipay/common[v2.5.1, v3.0.2].
    - Installation request for omnipay/common (locked at v3.0.2) -> satisfiable by omnipay/common[v3.0.2].


Installation failed, reverting ./composer.json to its original content.

Braintree 6.x

Hi,

Are there any plans to move this project to v6 of braintree php?

I think this would bump the minimum requirement to php 7.3 but running on php 8.1 produces a significant number of deprecation warnings with v5 of the braintree package.

Thanks

Version 3 Tag?

Our application is relying on version ~3.0 of this package (which I believe was previously aliased to dev-master). This does not appear to be a tag that is available via composer, so we now have an issue with dependency installation. How can we install version 3 via composer?

Dependencies collisions omnipay/braintree + laravel/framework 5.6

Reproduce:
Add both Laravel and omnipay to a composer-require:

    "require": {
        "laravel/framework": "5.6.*",
        "omnipay/braintree": "*"
    },
    "minimum-stability": "dev",
    "prefer-stable": true,

run composer install

Full log in attatchment, the collision:
omnipay/braintree requires omnipay/common 2
omnipay/common 2 requires symfony/http-foundation 3
laravel/framework 5.6 requires symfony/http-foundation 4
omnipay/common 3 requires symfony/http-foundation 4

Upgrade to v3

Good day guys, is this integration going to be upgraded for Omnipay v3?

Dependency Issues

I've got minimum stability set to dev yet composer is unable to install, it has an issue resolving the braintree library dependencies.

  Problem 1
    - Installation request for omnipay/braintree ~2.0@dev -> satisfiable by omnipay/braintree[2.0.x-dev].
    - omnipay/braintree 2.0.x-dev requires braintree/braintree_php ^2.39|^3.0 -> no matching package found.

Potential causes:
 - A typo in the package name
 - The package is not available in a stable-enough version according to your minimum-stability setting
   see <https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion> for more details.

Need help for merchant account id

Hi,

Can anyone please let us know how can we pass merchantAccountId while generating the clientToken

$clientToken = $gateway->clientToken()->send()->getToken();

As it not clear from the code

Braintree package is not installing using composer

We are trying to install the braintree package in laravel 5.7 but it is throwing error.

PHP version at server is 7.2.24

  • nesbot/carbon 1.39.0 requires kylekatarnls/update-helper ^1.1 -> satisfiable by kylekatarnls/update-helper[1.1.0, 1.1.1, 1.2.0].

Can you please check and let us know the reason behind.

Use omnipay-braintree to pay with paypal

Hi,

which is the flow to make a payment with omnipay-braintree plugin?
Braintree allows to pay with paypal, but I can't find something like that with the omnipay-braintree gateway.

Best Regards

Webhooks Testing Gives Errors

Assumes:
Omnipay is setup correctly.
Omnipay makes a successful transaction to Braintree.
MerchantID, PublicKey & PrivateKey are set correctly.

$sampleNotificationSignature = 'WITHHELD';
$sampleNotificationPayload = 'WITHHELD';
use Omnipay\Omnipay;
$gateway = Omnipay::create('Braintree');
$gateway->setPrivateKey('WITHHELD');
$gateway->setPublicKey('WITHHELD');
$gateway->setMerchantId('WITHHELD');
$gateway->setTestMode(TRUE);
$notification = $gateway->parseNotification([
    'bt_signature'  => $sampleNotificationSignature,
    'bt_payload'    => $sampleNotificationPayload
])->send();

When trying to test WebHooks from Braintree, POST from the test url results in the following errors...

Fatal error: Uncaught Braintree\Exception\Configuration: Braintree\Configuration::merchantId needs to be set (or accessToken needs to be passed to Braintree\Gateway). in /vendor/braintree/braintree_php/lib/Braintree/Configuration.php:254

Stack trace:
#0 /vendor/braintree/braintree_php/lib/Braintree/WebhookNotificationGateway.php(10): Braintree\Configuration->assertHasAccessTokenOrKeys()
#1 /vendor/braintree/braintree_php/lib/Braintree/Gateway.php(257): Braintree\WebhookNotificationGateway->__construct(Object(Braintree\Gateway))
#2 /vendor/braintree/braintree_php/lib/Braintree/WebhookNotification.php(35): Braintree\Gateway->webhookNotification()
#3 /vendor/omnipay/braintree/src/Gateway.php(281): Braintree\WebhookNotification::parse('DETAILS HIDDEN')
#4 braintree.php(27 in /vendor/braintree/braintree_php/lib/Braintree/Configuration.php on line 254

I believe this must be an error in omnipay's code. I see no reason why this would fail when transactions, customer creation, payments and charges all post fine when submitting the shopping cart. I've created an issue for it on Stackoverflow.

https://stackoverflow.com/questions/48843652/omnipay-braintree-webhooks-testing-gives-errors

The code below works, essentially overriding omnipay and using braintree_php directly.

use Braintree_Gateway;
use Braintree_Configuration;
Braintree_Configuration::environment('sandbox');
Braintree_Configuration::merchantId('PRIVATE');
Braintree_Configuration::publicKey('PRIVATE');
Braintree_Configuration::privateKey('PRIVATE');

$sampleNotification = Braintree_WebhookTesting::sampleNotification(
    Braintree_WebhookNotification::SUBSCRIPTION_WENT_PAST_DUE,
    'my_id'
);

$webhookNotification = Braintree_WebhookNotification::parse(
    $sampleNotification['bt_signature'],
    $sampleNotification['bt_payload']
);

$webhookNotification->subscription->id;

print_r($webhookNotification);

A basic guide to using Braintree (with this lib)

Hi, i wanna use this package on a store am building. Problem is, i don't understand how Braintree works.

Can some one help explain how to use braintree with this package? Am confused about generating payment method nonce, token etc.

Any help i can get would be appreciated.

Cc @1ed @iampersistent .

Set Merchant Account ID?

Is there a way of setting up the "Merchant Account ID" parameter? (for a common merchant id there can be multiple accounts). Tried the following but doesn't appear to work:

    $gateway->updateMerchantAccount(
        ['merchantAccountId' => account_id]
    );

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.