Laravel 5.3 How to use Braintree\WebhookNotification - laravel

I am using Laravel 5.3 and trying to add new webhook event handler in WebhookController
Here is my controller
namespace App\Http\Controllers;
use Braintree\WebhookNotification;
use Laravel\Cashier\Http\Controllers\WebhookController as CashierController;
use Log;
use App\Models\BraintreeMerchant;
class WebhookController extends CashierController
{
public function handleSubMerchantAccountApproved(WebhookNotification $notification)
{
if( isset($_POST["bt_signature"]) && isset($_POST["bt_payload"]))
{
$notification = Braintree_WebhookNotification::parse($_POST["bt_signature"], $_POST["bt_payload"]);
$notification->kind == Braintree_WebhookNotification::SUB_MERCHANT_ACCOUNT_APPROVED;
// true
$notification->merchantAccount->status;
// "active"
$notification->merchantAccount->id;
// "blue_ladders_store"
$notification->merchantAccount->masterMerchantAccount->id;
// "14ladders_marketplace"
$notification->merchantAccount->masterMerchantAccount->status;
}
}
}
but getting the following error message:
BindingResolutionException in Container.php line 763:
Target [Braintree\WebhookNotification] is not instantiable.

I've found the answer. this is how to implement Braintree webhook controller.
<?php
namespace App\Http\Controllers;
use Braintree\WebhookNotification;
use Laravel\Cashier\Http\Controllers\WebhookController as CashierController;
use Illuminate\Http\Request;
class WebhookController extends CashierController
{
public function handleSubMerchantAccountApproved(Request $request)
{
$notification = WebhookNotification::parse($request->bt_signature, $request->bt_payload);
$merchantId = $notification->merchantAccount->id;
$result_merchant_status = $notification->merchantAccount->status;
}
}

Related

Class "App\Http\Controllers\Auth\Mail" not found

How can I resolve this error? I am trying to customize the default email template on laravel. This is the code for the controller that sends the email.
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Http\Request;
use App\Models\User;
use Illumunate\Auth;
class EmailVerificationNotificationController extends Controller
{
public function store(Request $request)
{
if ($request->user()->hasVerifiedEmail()) {
return redirect()->intended(RouteServiceProvider::HOME);
}
Mail::send('email.template', $request->user(), function($mail) use($data){
$mail->to($request->user()->email, 'no-reply')->subject("Verify Email Address");
$mail->from('admin#raketlist.com','testing');
});
$request->user()->sendEmailVerificationNotification();
return back()->with('status', 'verification-link-sent');
}
}
Add use Illuminate\Support\Facades\Mail; to other uses.

How to pass variable from Controller to Nova Recource?

I want to pass $defaultFrom from NewsletterController.php:
<?php
namespace App\Http\Controllers;
use App\Mail\NewsletterMail;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Mail;
class NewsletterController extends Controller
{
public function send()
{
$defaultFrom = 'newsletter#stuttard.de';
DB::table('newsletter_mails')->insert(['from' => $defaultFrom]);
$emails = DB::select('select * from newsletters order by id desc');
foreach ($emails as $email) {
Mail::to($email)->send(new NewsletterMail());
}
}
}
to NewsletterMail.php:
<?php
namespace App\Nova;
use Illuminate\Http\Request;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Text;
class NewsletterMail extends Resource
{
public function fields(Request $request)
{
return [
ID::make(__('ID'), 'id')->sortable(),
Text::make('From', 'from')->default($defaultFrom)->placeholder($defaultFrom),
];
}
}
I've tried to put public $defaultFrom; above the fields() function or call new NewsletterMail($defaultFrom) but this seems to be wrong syntax. Sorry, I'm a bit new to Laravel.
I assume that you have Newsletter model. Move $defaultFrom to model as public const DEFAULT_FROM = 'newsletter#stuttard.de';. After doing this, you can call it's value in both places using Newsletter::DEFAULT_FROM.

Laravel 5.7 SendEmail is not working properly

I am sending email using laravel 5.7 but i found following error " (1/1) FatalErrorException
Class 'App\Mail\UserRequest' not found" Need help
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Mail;
//use \App\Mail\SendMail;
use App\Mail\UserRequest;
class ContactusController extends Controller
{
public function index()
{
return view('contactus');
}
public function sendmail(Request $req)
{
$msgdata = array('subject'=>$req->subject,'email'=>$req->email,
'name'=>$req->name,'body'=>$req->message);
Mail::to('dddddddd#dddsdsf.com')->send(new UserRequest($msgdata));
return view('contactus');
}
}

Call to undefined method Illuminate\Notifications\Notification::send()

I am trying to make a notification system in my project.
These are the steps i have done:
1-php artisan notifications:table
2-php artisan migrate
3-php artisan make:notification AddPost
In my AddPost.php file i wrote this code:
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
class AddPost extends Notification
{
use Queueable;
protected $post;
public function __construct(Post $post)
{
$this->post=$post;
}
public function via($notifiable)
{
return ['database'];
}
public function toArray($notifiable)
{
return [
'data'=>'We have a new notification '.$this->post->title ."Added By" .auth()->user()->name
];
}
}
In my controller I am trying to save the data in a table and every thing was perfect.
This is my code in my controller:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Post;
use App\User;
//use App\Notifications\Compose;
use Illuminate\Notifications\Notification;
use DB;
use Route;
class PostNot extends Controller
{
public function index(){
$posts =DB::table('_notification')->get();
$users =DB::table('users')->get();
return view('pages.chat',compact('posts','users'));
}
public function create(){
return view('pages.chat');
}
public function store(Request $request){
$post=new Post();
//dd($request->all());
$post->title=$request->title;
$post->description=$request->description;
$post->view=0;
if ($post->save())
{
$user=User::all();
Notification::send($user,new AddPost($post));
}
return redirect()->route('chat');
}
}
Everything was good until I changed this code:
$post->save();
to this :
if ($post->save())
{
$user=User::all();
Notification::send($user,new AddPost($post));
}
It started to show an error which is:
FatalThrowableError in PostNot.php line 41: Call to undefined method
Illuminate\Notifications\Notification::send()
How can i fix this one please??
Thanks.
Instead of:
use Illuminate\Notifications\Notification;
you should use
use Notification;
Now you are using Illuminate\Notifications\Notification and it doesn't have send method and Notification facade uses Illuminate\Notifications\ChannelManager which has send method.
Using this
use Illuminate\Support\Facades\Notification;
instead of this
use Illuminate\Notifications\Notification;
solved the problem for me.
Hope this helps someone.
using this is better
use Notification
Instead of
use Illuminate\Support\Facades\Notification
this makes the send() not accessible [#Notification Databse]

Facade not found by AliasLoader in Laravel

I added a custom facade to my 'config/app.php' in my laravel project under 'aliases'
'GeoLocation' => '\App\Facades\GeoLocation',
The folder of the custom class is in 'app/Facades/GeoLocation.php' and the service provider in 'app/Providers/GeoLocationServiceProvider.php'
How do I need to state the correct alias in the app.php to be able to load the Facade correctly? The error message is:
ErrorException in AliasLoader.php line 63:
Class 'Facades\GeoLocation' not found
This is my facade:
<?php namespace App\Facades;
use Illuminate\Support\Facades\Facade;
class GeoLocation extends Facade {
protected static function getFacadeAccessor() { return 'geolocation'; }
}
Could it be that the return value of my service provider is incorrect?
<?php namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class GeoLocationServiceProvider extends ServiceProvider {
public function register() {
\App::bind('geolocation', function()
{
return new GeoLocation;
});
}
}
For a test I created another service provider called custom function:
<?php namespace App\Helpers;
class CustomFunction {
//Generate random float between -1 and 1
function f_rand($min = 0, $max = 1, $mul = 1000000) {
if ($min>$max) return false;
return mt_rand($min*$mul, $max*$mul) / $mul;
}
function test() {
echo "OK";
}
}
<?php namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class CustomFunctionServiceProvider extends ServiceProvider {
public function register() {
\App::bind('customfunctions', function()
{
return new CustomFunction;
});
}
}
the simplest way is to change the namespace to the file app/Facades/GeoLocation.php' to App\Facades;
then update aliase registration to
'GeoLocation' => 'App\Facades\GeoLocation',

Resources