Saving Mandrill webhook to database - laravel-4

Im having trouble understanding how to process the data sent to my post route from the mandrill webhook.
I have set up my route and registered it in the mandrill settings. Sending a test from the dashboard works fine (webhook is triggered on send, open, and hard_bounce):
Route::post('/mailApi/webhooks', 'ContactController#postMandrill');
Currently, I'm just trying to ensure that I can receive the webhook and make sure that I understand the format.
I have created a function for in my ContactController for testing purposes:
public function postMandrill(){
$data = Input::get("mandrill_events");
$mandrill = new Mandrillemail;
$mandrill->event = $data;
$mandrill->msg_subject = 'test';
$mandrill->save();
}
When I send an email to trigger the webhook, I get no errors and nothing is saved in the database. It seems like the route isn't touched at all. What do I need to do to access the webhook?

Related

Laravel 5.7 verification email has wrong url when sending email through event

I'm trying to use laravel's 5.7 email verification to send an email when an account is registered. I have an event that fires that send the url when a user is registered. The event dispatch can be seen here.
protected function registered(Request $request, $user)
{
UserRegistered::dispatch($user);
}
The event fires and a listener sends an email by using the following code.
public function handle(UserRegistered $event)
{
$event->user->notify(new VerifyEmail);
}
This then does send the email verification mail to my email address so the event is working. However the issue I'm having is the verification email link that is contained in the email is incorrect.
http://localhost/email/verify/19?expires=1544182945&signature=b4337e1c7e07a7e7117a8696a30b456ab2a304cdea563ca7aea6c90bb9a2541f
Here is what is being sent by email. However the app url should not be localhost and instead by core-site.test. e.g. http://core-site.test/email/verify etc...
Does anyone know why the url is incorrect and how I can fix it?

Debugging/Testing stripe webhook calls to Laravel Spark

I am currently testing Stripe webhooks using the latest Laravel Spark. I've got a Stripe account working, meaning that I can add (fake) creditcards and charge subscriptions/single payments. Next, I am using a fake hook endpoint (ultrahook.com) to retrieve webhooks requests from Stripe.
My vanilla route file is from the Spark installation:
$router->post('/webhook/stripe', 'Settings\Billing\StripeWebhookController#handleWebhook');
And should handle all the webhooks fine. To test the webhooks, I checked the StripeWebhookController object and changed a method to log some info:
protected function handleInvoicePaymentSucceeded(array $payload)
{
Log::info('This is some useful handleInvoicePaymentSucceeded.');
}
However, nothing gets logged when I call run a Stripe test webhook of type: invoice.payment_succeeded.
I do see the request coming into the ultrahook console and it gets returned a 200. I can also copy paste the JSON Stripe test webhook and paste it into Postman after which it gets send to http://localhost:80/webhook/stripe ... again a 200 response but nothing logged.
Any advice?
Laravel Cashier instructs you to exclude the webhook routes from VerifyCsrfToken middleware as stated here:
https://laravel.com/docs/5.5/billing#handling-stripe-webhooks
Spark uses Cashier, I'd imagine you need to do the same then.
Well, it appears that I needed to add
CASHIER_ENV=testing
in the env file. Nice to see that in the documentation Laravel... not
stripe webhooks don't call localhost, it should have a domain name to call.
you may use ultrahook gem for that..
it will create a temporary binding url which you can provide in stripe dashboard as callback url
like this
ultrahook stripe 80
which would give you an url that you map it in stripe dashboard
http://stripe.somename.ultrahook.com -> http://localhost:80
NOTE: You can access this url on a browser, it is just a virtual binding

Testing event send email in Laravel

I am creating a RESTFUL API for forgot password feature in my Laravel project. I finished it.
However, I don't know how to build unittest to testing event send email occurred?
How do I build it?
$mock = Mockery::mock('Swift_Mailer');
$this->app['mailer']->setSwiftMailer($mock);
$mock->shouldReceive('send')->once()
->andReturnUsing(function($msg) {
$this->assertEquals('My subject', $msg->getSubject());
$this->assertEquals('foo#bar.com', $msg->getTo());
$this->assertContains('Some string', $msg->getBody());
});
you can see this:
Laravel unit testing emails

Laravel's Mail notification won't send, but Laravel's Mail::Raw will

I have configured my SMTP server correctly in Laravel's env file, and can successfully send an email using Mail::raw e.g.
Mail::raw("This is a test message", function ($message)
{
$message->from(env("MAIL_ORDER_ADDRESS"), 'Orders');
$message->to('user#example.com');
$message->subject('Test Message');
});
However, when I use a laravel 5.3 mail notification, no email is received (nor is an error generated). I have tested the same notification code locally using mail trap and the notifications work correctly.
I can't understand how if the mail server is working and can be used with Mail::raw, it doesn't automatically work with notifications when I have tested locally and confirm they are coded correctly.
Note: Using shared hosting on NameCheap.
Any ideas?
FIXED: It was because I had not configured "From" in config/mail.php and because the domains didn't match, it wasn't set.
The opposite situation is occurring for me. I have the MAIL_DRIVER=mail set within the .env file.
I have set MAIL_FROM_ADDRESS & MAIL_FROM_NAME within the .env file and viewed the app/config/mail.php
Mail::raw is sending out email correctly via the Postfix logs but any emails sent via the new Laravel 5.3 Notifications is not working. No errors or any information writing to the logs.
There appears to be some other issue occurring.
I had the same issue. During testing for Mail::raw, i had set MAIL_ENCRYPTION to empty.
When I set MAIL_ENCRYPTION=tls for notify email, it started working.

How to avoid 'Choose Account' screen with Google Calendar API?

Our app is importing the next 1000 events from a user's Google calendar API. We ran into the problem where nginx would timeout. To get around this I'm putting the pagination data into a session variable and making separate HTTP requests to the API. This works except for one problem: every time we make a new HTTP request the API asks the user to choose which account they want to use (one user with multiple gmail accounts). I would have thought that the pagination data would include account selection but this is apparently not the case. How can I programmatically select the email account within the HTTP request?
You can store it once
public static void setmCredential(GoogleAccountCredential _mCredential) {
mCredential = _mCredential;
mService = new com.google.api.services.calendar.Calendar.Builder(
transport, jsonFactory, mCredential)
.setApplicationName("YourApplicationName")
.build();
}
And then when caliing pass it like this
new MakeRequestTask(AccountCredential.mService).execute();

Resources