braintree / braintree_php

Braintree PHP library
https://developer.paypal.com/braintree/docs/start/overview
MIT License
544 stars 225 forks source link

Braintree Webhook stuck at Call to undefined method Braintree\Gateway::webhookNotification() #213

Closed vickymessii closed 6 years ago

vickymessii commented 6 years ago

General information

Issue description

I am using PHP SDK for Braintree Market Place Payment,Need to Webhook Notifications , I tried to implement webhook but I can't figure out this. I got this error Call to undefined method Braintree\Gateway::webhookNotification()

I am using this Code The Amount and payment_method_nonce is Coming from Dropin Ui braintree For Single Payment and also without Webhook Notification its working fine.

<?php
require_once("../includes/braintree_init.php");

$amount = $_POST["amount"];
$nonce = $_POST["payment_method_nonce"];

$merchantAccountParams = [
  'individual' => [
    'firstName' => 'Jane',
    'lastName' => 'Doe',
    'email' => 'jane@14ladders.com',
    'phone' => '5553334444',
    'dateOfBirth' => '1981-11-19',
    'ssn' => '456-45-4567',
    'address' => [
      'streetAddress' => '111 Main St',
      'locality' => 'Chicago',
      'region' => 'IL',
      'postalCode' => '60622'
    ]
  ],
  'business' => [
    'legalName' => 'Jane\'s Ladders',
    'dbaName' => 'Jane\'s Ladders',
    'taxId' => '98-7654321',
    'address' => [
      'streetAddress' => '111 Main St',
      'locality' => 'Chicago',
      'region' => 'IL',
      'postalCode' => '60622'
    ]
  ],
  'funding' => [
    'descriptor' => 'Blue Ladders',
    'destination' => Braintree_MerchantAccount::FUNDING_DESTINATION_BANK,
    'email' => 'funding@blueladders.com',
    'mobilePhone' => '5555555555',
    'accountNumber' => '1123581321',
    'routingNumber' => '071101307'
  ],
  'tosAccepted' => true,
  'masterMerchantAccountId' => "jonestechsolutionsllc",
  //'id' => "9m63s6"
];
$result = $gateway->merchantAccount()->create($merchantAccountParams);

$sampleNotification = $gateway->webhookTesting()->sampleNotification(
    Braintree_WebhookNotification::SUB_MERCHANT_ACCOUNT_APPROVED,
    $result->merchantAccount->id
);

$webhookNotification = $gateway->webhookNotification()->parse(
    $sampleNotification['bt_signature'],
    $sampleNotification['bt_payload']
);

$webhookNotification->subscription->id;

$res = $gateway->transaction()->sale([
  'merchantAccountId' => $result->merchantAccount->id,
  'amount' => '10.00',
  'paymentMethodNonce' => $nonce,
  'serviceFeeAmount' => "1.00"
]);
print_r($webhookNotification);
print_r($res);
exit;

In My Error Log I got this Error

Call to undefined method Braintree\Gateway::webhookNotification()

Anyone can help?

crookedneighbor commented 6 years ago

It's very strange to see Call to undefined method Braintree\Gateway::webhookNotification() in your error logs, because that is definitely defined: https://github.com/braintree/braintree_php/blob/1307b7c7ab0fc05a0dc8f2492acd9003a06ca298/lib/Braintree/Gateway.php#L255

I would have expected to see Call to undefined method Braintree\Gateway::webhookTesting(), which is currently missing and I'm working on adding it.

Are you sure it says webhookNotification and not webhookTesting?

If I change $sampleNotification = $gateway->webhookTesting()->sampleNotification( to $sampleNotification = Braintree_WebhookTesting()->sampleNotification(, it proceeds past that point. Not sure why you're trying to pull a subscription id off of the merchant account approved webhok, but if I remove that line, the rest works with the modification.

vickymessii commented 6 years ago

I got both errors

[14-Mar-2018 14:44:17 UTC] PHP Fatal error:  Call to undefined method Braintree\Gateway::webhookTesting() in /checkout.php on line 47
[14-Mar-2018 14:44:17 UTC] PHP Fatal error:  Call to undefined method Braintree\Gateway::webhookNotification() in /webhook.php on line 9

You means to say i have to remove subscription id ?? am i right ??

vickymessii commented 6 years ago

have a look at Webhook.php

<?php
ini_set('display_errors', 1);
require_once("../includes/braintree_init.php");

if (
    isset($_POST["bt_signature"]) &&
    isset($_POST["bt_payload"])
) {
     $webhookNotification = $gateway->webhookNotification()->parse(
        $_POST["bt_signature"], $_POST["bt_payload"]
    );

    // Example values for webhook notification properties
    $message = $webhookNotification->kind; // "subscription_went_past_due"
    $message = $webhookNotification->timestamp->format('D M j G:i:s T Y'); // "Sun Jan 1 00:00:00 UTC 2012"

    file_put_contents("/tmp/webhook.log", $message, FILE_APPEND);
}
crookedneighbor commented 6 years ago

I'm unable to reproduce and nothing in that file looks wrong to me, so my guess is something isn't being set correctly braintree_init.php. Please contact our support team and reference this github issue so we can further dig into what's wrong with your integration.

https://articles.braintreepayments.com/forms/contact

vickymessii commented 6 years ago

I have setup the braintree_init.php properly because if the incorrect is in braintree_init.php I can't create the submerchant account. but its creating the submerchant and also doing payment if i skip the webhook step. I thing i need to know can i do the payment without Webhook??

crookedneighbor commented 6 years ago

I still recommend contacting our support team. They'll be better equipped to help you debug your integration.

vickymessii commented 6 years ago

Ok Thanks

vickymessii commented 6 years ago

Hey,

Now I got new Error Uncaught exception 'Braintree\Exception\Configuration' with message 'Braintree\Configuration::merchantId needs to be set (or accessToken needs to be passed to Braintree\Gateway).

Question is that if my merchant ID is not how its creating sub merchant because i able to see sub merchant account in my dashboard but i am going to call this method:

$webhookNotification = Braintree\WebhookNotification::parse($sampleNotification['bt_signature'], $sampleNotification['bt_payload']);

it says Uncaught exception 'Braintree\Exception\Configuration' with message 'Braintree\Configuration::merchantId needs to be set (or accessToken needs to be passed to Braintree\Gateway).

crookedneighbor commented 6 years ago

That suggests to me that your configuration is not set up correctly. I noticed that you're using Braintree\WebhookNotification instead of the $gateway variable, so you'll need to set up the global configuration:

Braintree\Configuration::environment('sandbox'); // or production
Braintree\Configuration::merchantId('your_merchant_id');
Braintree\Configuration::publicKey('your_public_id');
Braintree\Configuration::privateKey('your_private_key');

I still think this is an issue with your specific integration, and not the SDK, so it's better handled by contacting support. They can help you dig into the specifics of your integration.