1

I transaction state is not getting updated at Magento when it changes at Braintree. I manually want to get the transaction status from Braintree but unable to call the Braintree method in my custom module. Any sugesstion how can I call Braintree method and get the status of transaction?

$gateway->transaction()->search([
  Braintree_TransactionSearch::status()->is(Braintree_Transaction::SETTLED)
]);

I want to call this method.

2
  • Add what you have untill now May 31, 2018 at 14:16
  • That is what I need to know. I have created a helper already but in that I am unable to get the instance of Braintree Adapter. Jun 1, 2018 at 5:57

1 Answer 1

2

Somethink like this

namespace Vendore\ModuleName\Helper\Braintree;
use Magento\Braintree\Model\Adapter\BraintreeAdapterFactory;
use Magento\Braintree\Model\Adapter\BraintreeSearchAdapter;


class Status extends AbstractHelper {

    private $braintreeAdapterFactory;
    /**
     * @var BraintreeSearchAdapter
     */
    private $braintreeSearchAdapter;

    /**
     * Status constructor.
     * @param BraintreeAdapterFactory $braintreeAdapterFactory
     * @param BraintreeSearchAdapter $braintreeSearchAdapter
     */
    public function __construct(
        BraintreeAdapterFactory $braintreeAdapterFactory,
        BraintreeSearchAdapter $braintreeSearchAdapter
        ) {
        $this->braintreeAdapterFactory = $braintreeAdapterFactory;
        $this->braintreeSearchAdapter = $braintreeSearchAdapter;
    }

    /**
     * @param $transactionId
     * @return mixed
     */
    public function get($transactionId)
    {
        $braintreeAdapter = $this->braintreeAdapterFactory->create();
        $collection = $braintreeAdapter->search(
            [
            $this->braintreeSearchAdapter->id()->is($transactionId)
            ]
            );

        //add some check if we got correct response
        //and  get status
        return $collection->firstItem()->status;
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.