4

Whenever, I create a transaction via Braintree API, or via their sandbox, it goes through many statuses like Authorized, Submitted for Settlement, Settled ... and all this takes 24 hours approximately. I want to ask is there a way by which I can create a transaction in sandbox/api and it is settled or disputed instantly. I don't know why it takes so much time ... e.g. in online shopping my credit card is charged immediately. How can same be achieved via braintree payments sandbox ?

Haris ur Rehman
  • 2,593
  • 30
  • 41

2 Answers2

8

I work at Braintree. It looks like we already responded to your support email, but I'll post this here for others who have the same problem.

Each client library has a method to instantly settle a transaction in Sandbox. For PHP, it's in the TestHelper:

class Braintree_TestHelper
{
    . . .

    public static function settle($transactionId)
        {
            $http = new Braintree_Http(Braintree_Configuration::$global);
            $path = Braintree_Configuration::$global->merchantPath() . '/transactions/' . $transactionId . '/settle';
            $http->put($path);
        }

    . . .
}

In production, any transaction that you run will generally show up as a charge on a credit card instantly, but it isn't "permanent" and the money won't actually move until the transaction has settled. In other words, even though settlement can take 24 hours, the charge doesn't take that long to show up on the card.

agf
  • 171,228
  • 44
  • 289
  • 238
  • I followed this approach of settling a transaction. It settled the transaction on sandbox, but it didn't invoke the "Transaction disbursed" webhook i set on the sandbox. Any reason for that? The webhook is called properly when transaction settles without the api call. – Haris ur Rehman Mar 27 '15 at 22:45
  • The disbursement happens on a set schedule even when you manually trigger settlement. You should receive the webhook sometime after 04:15 UTC. – agf Mar 28 '15 at 02:23
  • @agf can you explain a bit more? I'm using Braintree with composer (autoload and stuff) and `Braintree_TestHelper::settle('someid');` does not work, should I include the class separately. Also, this `settle` method can be used anywhere? Transaction id must be a valid transaction object? Thanks – viarnes Jul 15 '15 at 14:52
  • Sorry, by "does not work" I meant `Fatal error: Class 'Braintree_TestHelper' not found` – viarnes Jul 15 '15 at 14:57
  • @viarnes Yes, you have to require the test helper separately. – agf Jul 15 '15 at 20:17
  • @viarnes If you're using the composer braintree classes do this: `\Braintree\Test\Transaction::settle('someid');` – JonTroncoso Jan 16 '17 at 20:11
1

Things have slightly changed since the answer. The idea is the same, but as of the 2023 version of the PHP SDK, this is a possible way to "force-settle" a transaction:

use Braintree\Configuration;

Configuration::environment('sandbox');
Configuration::merchantId('yourmid');
Configuration::publicKey('yourpbk');
Configuration::privateKey('yourprk');
Configuration::gateway()->testing()->settle('transactionid');
Attila Fulop
  • 6,861
  • 2
  • 44
  • 50